Hello World

Author: OA Lab, NWFSC Title: Respirometry Trials for Summer Krill 2019 Date: December 2020 - February 2021

Version Check

Libraries

Respirometry and Project End Determining Factors for Project End

Goals Our goal is to have 4 lipid samples from each MOAT at the end of the study. A wild cohort was measured for both their size and wet weight. Whole body morts were measured to get a sense of the size for the animals.
End of Study Determinations. End of the Study was biomass dependent to be able to accomplish Lipid analysis preparation.

In short 72 animals were selected for respirometry. Upwards of 200 animals (including those used in respirometry trials) were prepared in the last four days of the experiment to be included in lipid analysis.

Determining how to populate animals into respirometry trials Krill Doctrine 1. Krill needed to fast for 24hours prior to respirometry and lipids analysis preparation 2. Choose MOATs with the lowest number of animals remaining for the first round(s) of respirometry and follow on preparation for lipids analysis 3. Balance between MOATs across days of respirometry* 4. Balance between Treatments when choosing which respirometry round 5. Must achieve 4 vials per MOATs 6. Achieve 15-20 animals across treatments for respirometry 7. Wait until Night Time Conditions begin for the Krill to start Respirometry Trials. The night period for krill began at 1230pm.

Krill Doctrine Version 1

Krill Doctrine Version 1 Explained

1.) Setting Working Directory

#*********************************
## 1.) Setting Working Directory
#*********************************

#set working directory to the correct folder
setwd("/Users/katherinerovinski/GIT/NWFSC.MUK_KRL2019respirometrySLOPES")

2.) DF Creation

#*********************************
## 2.) Creating the intial Dataframe, dRESP
#*********************************

## Method 1 - 1 file for the four trials
#get all the files in the defined working directory that are in csv format  
dRESP <- read.csv(file = "KRILL_Resp_alltrials.csv", stringsAsFactors = FALSE)
dim(dRESP)
## [1] 3756   52
#write.csv(dRESP, file = "2020.11.30_presenseSENSORONLY.alltrials.data.csv", row.names = FALSE)
#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |


# dRESPanimal represents just the animal, vial, MOATs, etc.  
dRESPanimal <- read.csv(file = "RespirometryTrials_all.Animal.Info.csv") 
dim(dRESPanimal)
## [1] 76 11
#write.csv(dRESPanimal, file = "2020.11.30_krillanimaldata.csv", row.names = FALSE)
#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |


#dRESPmsr represents the measurements made by the presense optical device for Dissolved Oxygen 
dRESPmsr <- merge(dRESP, dRESPanimal, by="SensorName")

#write.csv(dRESPmsr, file = "2020.12.01_respirometrymeasurements.csv", row.names = FALSE)
#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |


# dRESP$MOATS <- factor(dRESP$MOATS)
# Checking the names of the different levels
# levels(dRESP$MOATS)


# dRESPmsr <- dRESPmsr %>% filter(!MOATS %in% c("3", "4", "5", "11")) %>%
#   filter(Treatment %in% c("CUR", "CHG", "TMP")) 
# 
# 
# dRESPmsr <- dRESPmsr %>% filter(!MOATS %in% c("3", "4", "5", "11")) %>%
#   filter(Treatment %in% c("CUR", "CHG", "TMP", "n/a")) 

Creating dRESPmsr- dataframe

3.) dateTime objects

#*********************************
## 3.) Creating dateTime objects  
#*********************************

dRESPmsr$dateTime <- ""
dRESPmsr$dateTime <- as.POSIXct(paste(dRESPmsr$Date,
                                      dRESPmsr$Time), "%d-%B-%y %H:%M:%S", tz="UTC")

# QA check
dim(dRESPmsr)
## [1] 3756   63
dRESPmsr$Time <- as.POSIXct(dRESPmsr$dateTime, format="%H:%M:%S")

4.) Observation naming

#*********************************
## 4.) Cleaning up observations  
#********************************

#Removing items with faulty sensor names
dRESPmsr <- subset(dRESPmsr, SensorName != "")

dRESPmsr$SensorName <- str_trim(dRESPmsr$SensorName, side = c("both"))
dRESPmsr$SensorName <- factor(dRESPmsr$SensorName)
dim(dRESPmsr)
## [1] 3756   63
dRESPmsr <- subset(dRESPmsr, Value != "---")

# Confirming proper number of krill 
# 76, 4x19 propoer number of animals under observation 
unique(dRESPmsr$SensorName)
##  [1] KrilLR11 KrilLR12 KrilLR13 KrilLR14 KrilLR15 KrilLR16 KrilLR17 KrilLR18
##  [9] KrilLR19 KrILR110 KriLR111 KriLR112 KriLR113 KriLR114 KriLR115 KriLR116
## [17] KriLR117 KriLR118 KriLR119 KriLR220 KriLR221 KriLR222 KriLR223 KriLR224
## [25] KriLR225 KriLR226 KriLR227 KriLR228 KriLR229 KriLR230 KriLR231 KriLR232
## [33] KriLR233 KriLR234 KriLR235 KriLR236 KriLR237 KriLR238 KRLr3_39 KRLr3_40
## [41] KRLr3_41 KRLr3_42 KRLr3_43 KRLr3_44 KRLr3_45 KRLr3_46 KRLr3_47 KRLr3_48
## [49] KRLr3_49 KRLr3_50 KRLr3_51 KRLr3_52 KRLr3_53 KRLr3_54 KRLr3_55 KRLr3_56
## [57] KRLr3_57 KRLr4_58 KRLr4_59 KRLr4_60 KRLr4_61 KRLr4_62 KRLr4_63 KRLr4_64
## [65] KRLr4_65 KRLr4_66 KRLr4_67 KRLr4_68 KRLr4_69 KRLr4_70 KRLr4_71 KRLr4_72
## [73] KRLr4_73 KRLr4_74 KRLr4_75 KRLr4_76
## 76 Levels: KrilLR11 KrilLR12 KrilLR13 KrilLR14 KrilLR15 KrilLR16 ... KRLr4_76
UniqueSensorNames <- levels(dRESPmsr$SensorName)
write.table(UniqueSensorNames, file = "2020.11.30DRESPmsr_UniqueSensorNames.csv")
#kable(UniqueSensorNames)

#5.) Trial ID & Krill ID

5.a Round Variable

5.b KrillID (grp & time)

6.) DO Corrections

#*********************************
## 6.) DO trial 3 correction applied to all rounds   
#*********************************

# New values to correct the DO values for the temperature in Trial 3 in the dataframe dRESPmsr

dRESPmsr$percentDOassumpt <- ""
dRESPmsr$assumedSatDOmg <- ""
dRESPmsr$percentDO <- ""
dRESPmsr$obseveredSatDOmg <- ""
dRESPmsr$actualDOmg <- ""

dRESPmsr$percentDOassumpt <- as.numeric(dRESPmsr$percentDOassumpt)
dRESPmsr$assumedSatDOmg <- as.numeric(dRESPmsr$assumedSatDOmg)
dRESPmsr$percentDO <- as.numeric(dRESPmsr$percentDO)
dRESPmsr$obseveredSatDOmg <- as.numeric(dRESPmsr$obseveredSatDOmg)
dRESPmsr$actualDOmg <- as.numeric(dRESPmsr$actualDOmg)
#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

#Correct Temperature
dRESPmsr$CorTemp <- 11

#Salinity Constant
dRESPmsr$SalinityConstant <- 30.3
#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# Numeric Corrections to DO value
dRESPmsr$Value <- as.numeric(dRESPmsr$Value)

dRESPmsr$assumedSatDOmg <- oxySol(dRESPmsr$CorTemp, 
                                  dRESPmsr$SalinityConstant)

dRESPmsr$percentDOassumpt <- dRESPmsr$Value / dRESPmsr$assumedSatDOmg

dRESPmsr$obseveredSatDOmg <- oxySol(dRESPmsr$CorTemp, dRESPmsr$SalinityConstant)

dRESPmsr$percentDO <- dRESPmsr$Value / dRESPmsr$assumedSatDOmg

dRESPmsr$actualDOmg <- dRESPmsr$percentDO * dRESPmsr$obseveredSatDOmg


#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

vialVol <- 0.02806 #liters (rather than 28.06mL)

oxygen <- vialVol * dRESPmsr$actualDOmg   
##mg per liter is the units for Oxygen per vial

dRESPmsr$oxygen <- oxygen

6.a) DO table & DO correction Plot Check

#*********************************
## 6.a) DO table & DO correction Plot Check  
#*********************************

# # write.table(dRESPmsr, file = "2020.11.06.dRESPmeasurements", sep=";", 
# #             row.names = TRUE)
# # 
# # dRESPmsr <-subset(dRESPmsr, actualDOmg != "---")
# # dRESPmsr$Time <- as.POSIXct(dRESPmsr$Time, format="%H:%M:%S")
# ggplot(dRESPmsr, aes(x = Time, y = actualDOmg, colour = SensorName)) +
#   geom_point(size = 1) +
#   geom_smooth(method = "lm") +
#   facet_wrap(~TrialID) +
#   #scale_y_continuous(breaks=seq(250,950,by=50))   +
#   theme_bw()

6.b DO Selections

#*********************************
## 6.a) DO table & DO correction Plot Check  
#*********************************

# 
# # Select by trial first
# T1dRESPmsr <- filter(dRESPmsr, TrialID == "Trial01")
# T2dRESPmsr <- filter(dRESPmsr, TrialID == "Trial02")
# T3dRESPmsr <- filter(dRESPmsr, TrialID == "Trial03")
# T4dRESPmsr <- filter(dRESPmsr, TrialID == "Trial04")

7.) Initial Dataframe dRESPmsr Plots, 80% DO, Oxygen Per Vial, Actual DOmg/L

Trial01 Loading Map

Trial01 Loading Map

7.1a) PLotting Percent DO filtering Trial 1

T1dRESPmsr <- filter(dRESPmsr, TrialID == "Trial01")

levels(T1dRESPmsr$Treatment)
## [1] "AMB" "CHG" "CUR" "n/a" "TMP"
ggplot(T1dRESPmsr, aes(x = Time, y = percentDO, colour = SensorName)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial01 Percent DO") +
  facet_wrap(~ Treatment) + 
  geom_hline(yintercept = c(.8), colour = "red") +
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

### 7.1a2) PLotting Percent DO filtering Trial 1 Colored by Round

T1dRESPmsr <- filter(dRESPmsr, TrialID == "Trial01")

levels(T1dRESPmsr$Treatment)
## [1] "AMB" "CHG" "CUR" "n/a" "TMP"
ggplot(T1dRESPmsr, aes(x = Time, y = percentDO, colour = T1dRESPmsr$RESPRound)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial01 Percent DO") +
  facet_wrap(~ Treatment) + 
  geom_hline(yintercept = c(.8), colour = "red") +
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

7.1b) Trial 1 Vial Oxygen over Time

ggplot(T1dRESPmsr, aes(x = Time, y = oxygen, colour = KrillID)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial01 Vial Oxygen over Time") +
  facet_wrap(~ Treatment) + 
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

7.1c) Trial01 Vial Oxygen over Time Organized by Round (1 of 8)

Depending on ordering there were animals that went all the way to ten rounds Likely that we will only consider rounds 01 through 08 due to 80% curve.

Goal in plotting animals by round is to see if there is a “temporal panic profile”. Do we need to wait long for an acclimation period? This will have implications on future respirometry protocols if a chase period is introduced.

ggplot(T1dRESPmsr, aes(x = Time, y = oxygen, colour = RESPRound)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial01 Vial Oxygen over Time Organized by Round (1 of 8)") +
  facet_wrap(~ Treatment) + 
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

Trial02 Loading Map

Trial02 Loading Map

7.2a) PLotting Percent DO filtering Trial 2

# T2dRESPmsr <- filter(dRESPmsr, TrialID == "Trial02") %>%
# c("CUR", "CHG", "TMP", "n/a"))

T2dRESPmsr <- filter(dRESPmsr, TrialID == "Trial02")
T2dRESPmsr <- T2dRESPmsr %>% filter(Treatment %in% c("CUR", "CHG", "TMP", "n/a"))


ggplot(T2dRESPmsr, aes(x = Time, y = percentDO, colour = SensorName)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial02 Percent DO- AmbientTreatmentRemoved") +
  facet_wrap(~ Treatment) + 
   geom_hline(yintercept = c(.8), colour = "red") +
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

7.2a) Trial 2 Vial Oxygen over Time

ggplot(T2dRESPmsr, aes(x = Time, y = oxygen, colour = KrillID)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial02 Vial Oxygen over Time") +
  facet_wrap(~ Treatment) + 
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

7.2c) Trial02 Vial Oxygen over Time Organized by Round (1 of 8)

Second Trial, Round 1 on 2019-10-28 began 18:50:01 Second Trial, Round 8 on 2019-10-28 ended 20:50:59

ggplot(T2dRESPmsr, aes(x = Time, y = oxygen, colour = RESPRound)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial02 Vial Oxygen over Time Organized by Round (1 of 8)") +
  facet_wrap(~ Treatment) + 
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

Trial03 Loading Map

Trial03 Loading Map

7.3) PLotting Percent DO filtering Trial 3

T3dRESPmsr <- filter(dRESPmsr, TrialID == "Trial03")


ggplot(T3dRESPmsr, aes(x = Time, y = percentDO, colour = SensorName)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial03 Percent DO") +
  facet_wrap(~ Treatment) + 
   geom_hline(yintercept = c(.8), colour = "red") +
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

7.3a) Trial 3 Vial Oxygen over Time

ggplot(T3dRESPmsr, aes(x = Time, y = oxygen, colour = KrillID)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial03 Vial Oxygen over Time") +
  facet_wrap(~ Treatment) + 
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

7.3c) Trial03 Vial Oxygen over Time Organized by Round (1 of 8)

ggplot(T3dRESPmsr, aes(x = Time, y = oxygen, colour = RESPRound)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial03 Vial Oxygen over Time Organized by Round (1 of 8)") +
  facet_wrap(~ Treatment) + 
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

Trial04 Loading Map

Trial04 Loading Map

7.4) PLotting Percent DO filtering Trial 4

T4dRESPmsr <- filter(dRESPmsr, TrialID == "Trial04")


ggplot(T4dRESPmsr, aes(x = Time, y = percentDO, colour = SensorName)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial04 Percent DO") +
  facet_wrap(~ Treatment) + 
   geom_hline(yintercept = c(.8), colour = "red") +
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

7.4a) Trial 4 Vial Oxygen over Time

ggplot(T4dRESPmsr, aes(x = Time, y = oxygen, colour = KrillID)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial04 Vial Oxygen over Time") +
  facet_wrap(~ Treatment) + 
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

7.4c) Trial04 Vial Oxygen over Time Organized by Round (1 of 8)

Acclimination period snuck in from the start Second Trial, Round 1 on 2019-10-29 began 17:23:01 Second Trial, Round 8 on 2019-10-29 ended 19:23:59

ggplot(T4dRESPmsr, aes(x = Time, y = oxygen, colour = RESPRound)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial04 Vial Oxygen over Time Organized by Round (1 of 8)") +
  facet_wrap(~ Treatment) + 
  theme_bw()
## `geom_smooth()` using formula 'y ~ x'

8.) Analysis, Respirometry - Creating the Slope Function

#*********************************
## 8.) Analysis, Respirometry - Creating the Slope Function  
#*********************************  

#nmol/vial; conversion for L to ml and umol to nmol cancels
#slope funcion of 2 vectors
slope <- function(y,x){
  return(lm(y~x, na.action = na.omit)$coefficients[2])
}
  
#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
dRESPmsr$delta_t <- as.numeric(dRESPmsr$delta_t)

cSlopes <- by(dRESPmsr, dRESPmsr$KrillID, function(x){ slope(x$oxygen, x$delta_t)})

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

#creating a data frame instead of a list 
ds <- as.data.frame(sapply(cSlopes, I))
#having row names be a variable in a column to be able to pull it out for later merging 
ds$TrialID<- row.names(ds)

9.) Merging ds and dRESPmsr

#add column to dslopes thats KrillID
#View(dref)
ds$KrillID <- row.names(ds)
#View(dslopes)
dtotal <- merge(dRESPmsr, ds, by = "KrillID")
#View(dtotal)

10.) Krill ID as a factor & Grouping by Krill ID

dtotal$KrillID <- factor(dtotal$KrillID)
nlevels(dtotal$KrillID)
## [1] 76

60 is the number of vials when Ambient Treatment is excluded

11.) Analysis, Respirometry - Creating Slope Functions & Linear Models

#*********************************
## 11.1) Creating the ds dataframe
#*********************************
# #get slopes and r^2 values from dtotal 

dSlopes <- data.frame(KrillID = levels(dtotal$KrillID))
# dSlopes$slope <- NA
# dSlopes$rsq <- NA

for(i in 1:length(dSlopes$KrillID)){
   m <- lm(oxygen ~ delta_t,
                         dtotal[dtotal$KrillID == dSlopes$KrillID[i],],
                         na.action=na.omit)
  dSlopes$slope[i] <- m$coefficients[2]
  dSlopes$rsq[i] <- summary(m)$r.squared
}

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

krillslopes <- merge(dtotal, dSlopes, by="KrillID")

dSlopes$SensorName <- ""

dSlopes <- dSlopes %>% group_by(KrillID)
dRESPanimal <- dRESPanimal %>% group_by(SensorName)

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

dSlopes$KrillID <- as.character(dSlopes$KrillID)
dSlopes$SensorName <- dRESPanimal$SensorName
dSlopes$TrialID <- dRESPanimal$TrialID
dSlopes$MOATS <- dRESPanimal$MOATS
dSlopes$Treatment<- dRESPanimal$Treatment
dSlopes$LoadingLocation<- dRESPanimal$LoadingLocation
dSlopes$VialNum<- dRESPanimal$GlassVialNumber
dSlopes$TelsonLength<- dRESPanimal$TelsonLength..mm.
dSlopes$WetWeight<- dRESPanimal$Size

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

12.0) Filtering krillslopes by each Trial

T1krillslopes <- filter(krillslopes, TrialID.x == "Trial01")
T2krillslopes <- filter(krillslopes, TrialID.x == "Trial02")
T3krillslopes <- filter(krillslopes, TrialID.x == "Trial03")
T4krillslopes <- filter(krillslopes, TrialID.x == "Trial04")

9.5) Filtering dtotal by each Trial and finding the 80% time

# ' ' ' ' 'TRIAL 01 ' ' ' ' ' ' ' 
# T1krillslopes <- filter(krillslopes, TrialID.x == "Trial01")
head(T1krillslopes$Time)
## [1] "2019-10-28 14:25:01 UTC" "2019-10-28 14:25:02 UTC"
## [3] "2019-10-28 14:25:03 UTC" "2019-10-28 14:25:53 UTC"
## [5] "2019-10-28 14:25:54 UTC" "2019-10-28 14:25:55 UTC"
#[1] "2019-10-28 14:25:01 UTC"


T1krillslopes80time <- filter(T1krillslopes, percentDO <=.8)
head(T1krillslopes80time$Time,1)
## [1] "2019-10-28 16:35:20 UTC"
#[1] "2019-10-28 16:35:20 UTC" 
T1krillslopes80 <- filter(T1krillslopes, Time <= as.POSIXct("2019-10-28 16:35:20", tz = "UTC"))
unique(T1krillslopes80$KrillID)
##  [1] Trial01_KrilLR11 Trial01_KrilLR12 Trial01_KrilLR13 Trial01_KrilLR14
##  [5] Trial01_KrilLR15 Trial01_KrilLR16 Trial01_KrilLR17 Trial01_KrilLR18
##  [9] Trial01_KrilLR19 Trial01_KrILR110 Trial01_KriLR111 Trial01_KriLR112
## [13] Trial01_KriLR113 Trial01_KriLR114 Trial01_KriLR115 Trial01_KriLR116
## [17] Trial01_KriLR117 Trial01_KriLR118 Trial01_KriLR119
## 76 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
#19levels

T1krillslopes <- T1krillslopes[order(T1krillslopes$Time),]

T1.80.start <- head(T1krillslopes$Time,1)
T1.80.stop <- tail(T1krillslopes80$Time,1)
T1.80_duration <- as.numeric(T1.80.stop - T1.80.start, units = "mins")
T1.80_duration
## [1] 4.5
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ' ' ' ' 'TRIAL 02 ' ' ' ' ' ' '
# T2krillslopes <- filter(krillslopes, TrialID.x == "Trial02")
head(T2krillslopes$Time,1)
## [1] "2019-10-28 18:55:21 UTC"
#[1] "2019-10-28 18:55:21 UTC"



T2krillslopes80time <- filter(T2krillslopes, percentDO <=.8)
head(T2krillslopes80time$Time,1)
## [1] "2019-10-28 21:12:23 UTC"
#[1] "2019-10-28 21:12:23 UTC" 
T2krillslopes80 <- filter(T2krillslopes, Time <= as.POSIXct("2019-10-28 21:12:23", tz = "UTC"))
unique(T2krillslopes80$KrillID)
##  [1] Trial02_KriLR220 Trial02_KriLR221 Trial02_KriLR222 Trial02_KriLR223
##  [5] Trial02_KriLR224 Trial02_KriLR225 Trial02_KriLR226 Trial02_KriLR227
##  [9] Trial02_KriLR228 Trial02_KriLR229 Trial02_KriLR230 Trial02_KriLR231
## [13] Trial02_KriLR232 Trial02_KriLR233 Trial02_KriLR234 Trial02_KriLR235
## [17] Trial02_KriLR236 Trial02_KriLR237 Trial02_KriLR238
## 76 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
# 11levels

T2krillslopes <- T2krillslopes[order(T2krillslopes$Time),]

T2.80.start <- head(T2krillslopes$Time,1)
T2.80.stop <- tail(T2krillslopes80$Time,1)
T2.80_duration <- as.numeric(T2.80.stop - T2.80.start, units = "mins")
T2.80_duration
## [1] 51.33333
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ' ' ' ' 'TRIAL 03 ' ' ' ' ' ' '
# T3krillslopes <- filter(krillslopes, TrialID.x == "Trial03")
head(T3krillslopes$Time)
## [1] "2019-10-29 14:06:22 UTC" "2019-10-29 14:06:23 UTC"
## [3] "2019-10-29 14:06:24 UTC" "2019-10-29 14:06:25 UTC"
## [5] "2019-10-29 14:15:17 UTC" "2019-10-29 14:15:18 UTC"
#[1] "2019-10-29 14:06:22 UTC"



T3krillslopes80time <- filter(T3krillslopes, percentDO <=.8)
head(T3krillslopes80time$Time,1)
## [1] "2019-10-29 15:45:19 UTC"
#[1] "2019-10-29 15:45:19 UTC" 
T3krillslopes80 <- filter(T3krillslopes, Time <= as.POSIXct("2019-10-29 15:45:19", tz = "UTC"))

unique(T3krillslopes80$KrillID)
##  [1] Trial03_KRLr3_39 Trial03_KRLr3_40 Trial03_KRLr3_41 Trial03_KRLr3_42
##  [5] Trial03_KRLr3_43 Trial03_KRLr3_44 Trial03_KRLr3_45 Trial03_KRLr3_46
##  [9] Trial03_KRLr3_47 Trial03_KRLr3_48 Trial03_KRLr3_49 Trial03_KRLr3_50
## [13] Trial03_KRLr3_51 Trial03_KRLr3_52 Trial03_KRLr3_53 Trial03_KRLr3_54
## [17] Trial03_KRLr3_55 Trial03_KRLr3_56 Trial03_KRLr3_57
## 76 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
#19levels

T3krillslopes <- T3krillslopes[order(T3krillslopes$Time),]

T3.80.start <- head(T3krillslopes$Time,1)
T3.80.stop <- tail(T3krillslopes80$Time,1)
T3.80_duration <- as.numeric(T3.80.stop - T3.80.start, units = "mins")
T3.80_duration
## [1] 57.3
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ' ' ' ' 'TRIAL 04 ' ' ' ' ' ' '
# T4krillslopes <- filter
head(T4krillslopes$Time)
## [1] "2019-10-29 17:20:22 UTC" "2019-10-29 17:20:23 UTC"
## [3] "2019-10-29 17:20:24 UTC" "2019-10-29 17:20:25 UTC"
## [5] "2019-10-29 17:43:31 UTC" "2019-10-29 17:43:32 UTC"
#[1] "2019-10-29 17:20:22 UTC"



T4krillslopes80time <- filter(T4krillslopes, percentDO <=.8)
head(T4krillslopes80time$Time,1)
## [1] "2019-10-29 18:43:56 UTC"
#[1] "2019-10-29 18:43:56 UTC" 
T4krillslopes80 <- filter(T4krillslopes, Time <= as.POSIXct("2019-10-29 18:43:56", tz = "UTC"))
unique(T4krillslopes80$KrillID)
##  [1] Trial04_KRLr4_58 Trial04_KRLr4_59 Trial04_KRLr4_60 Trial04_KRLr4_61
##  [5] Trial04_KRLr4_62 Trial04_KRLr4_63 Trial04_KRLr4_64 Trial04_KRLr4_65
##  [9] Trial04_KRLr4_66 Trial04_KRLr4_67 Trial04_KRLr4_68 Trial04_KRLr4_69
## [13] Trial04_KRLr4_70 Trial04_KRLr4_71 Trial04_KRLr4_72 Trial04_KRLr4_73
## [17] Trial04_KRLr4_74 Trial04_KRLr4_75 Trial04_KRLr4_76
## 76 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
#11levels

# 19+11+19+11
# 60

T4krillslopes <- T4krillslopes[order(T4krillslopes$Time),]

T4.80.start <- head(T4krillslopes$Time,1)
T4.80.start
## [1] "2019-10-29 17:20:22 UTC"
T4.80.stop <- tail(T4krillslopes80time$Time,1)
T4.80.stop
## [1] "2019-10-29 19:31:51 UTC"
T4.80_duration <- as.numeric(T4.80.stop - T4.80.start, units = "mins")
T4.80_duration
## [1] 131.4833

8.6) Bringing all trials back together following 80% DO selection)

krillslopes80 <- rbind(T1krillslopes80, T2krillslopes80, T3krillslopes80, T4krillslopes80)

8.7) Filtering krill slopes by each Trial and finding the 70% time

# ' ' ' ' 'TRIAL 01 ' ' ' ' ' ' ' 
# T1krillslopes <- filter(krillslopes, TrialID.x == "Trial01")
head(T1krillslopes$Time)
## [1] "2019-10-28 14:25:01 UTC" "2019-10-28 14:25:02 UTC"
## [3] "2019-10-28 14:25:03 UTC" "2019-10-28 14:25:53 UTC"
## [5] "2019-10-28 14:25:54 UTC" "2019-10-28 14:25:55 UTC"
#[1] "2019-10-28 14:25:01 UTC"

T1krillslopes70time <- filter(T1krillslopes, percentDO <=.7)
head(T1krillslopes70time$Time,1)
## POSIXct of length 0
#[1] POSIXct of length 0
# nothing got below 70% in trial #1
T1krillslopes70  <- T1krillslopes
unique(T1krillslopes70$KrillID)
##  [1] Trial01_KrilLR11 Trial01_KrilLR12 Trial01_KrilLR13 Trial01_KrilLR14
##  [5] Trial01_KrilLR15 Trial01_KrilLR16 Trial01_KrilLR17 Trial01_KrilLR18
##  [9] Trial01_KrilLR19 Trial01_KrILR110 Trial01_KriLR111 Trial01_KriLR112
## [13] Trial01_KriLR113 Trial01_KriLR114 Trial01_KriLR115 Trial01_KriLR116
## [17] Trial01_KriLR117 Trial01_KriLR118 Trial01_KriLR119
## 76 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
#19levels

T1krillslopes <- T1krillslopes[order(T1krillslopes$Time),]

T1.70.start <- head(T1krillslopes$Time,1)
T1.70.stop <- tail(T1krillslopes70$Time,1)
T1.70_duration <- as.numeric(T1.70.stop - T1.70.start, units = "mins")
T1.70_duration
## [1] 132.4667
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ' ' ' ' 'TRIAL 02 ' ' ' ' ' ' '
# T2krillslopes <- filter(krillslopes, TrialID.x == "Trial02")
head(T2krillslopes$Time)
## [1] "2019-10-28 18:55:21 UTC" "2019-10-28 18:55:22 UTC"
## [3] "2019-10-28 18:55:23 UTC" "2019-10-28 18:55:24 UTC"
## [5] "2019-10-28 18:55:33 UTC" "2019-10-28 18:55:34 UTC"
#[1] "2019-10-28 18:55:21 UTC"

T2krillslopes70time <- filter(T2krillslopes, percentDO <=.7)
head(T2krillslopes70time$Time,1)
## POSIXct of length 0
#OSIXct of length 0 - no values 
T2krillslopes70  <- T2krillslopes

unique(T2krillslopes70$KrillID)
##  [1] Trial02_KriLR220 Trial02_KriLR221 Trial02_KriLR222 Trial02_KriLR223
##  [5] Trial02_KriLR224 Trial02_KriLR225 Trial02_KriLR226 Trial02_KriLR227
##  [9] Trial02_KriLR228 Trial02_KriLR229 Trial02_KriLR230 Trial02_KriLR231
## [13] Trial02_KriLR232 Trial02_KriLR233 Trial02_KriLR234 Trial02_KriLR235
## [17] Trial02_KriLR236 Trial02_KriLR237 Trial02_KriLR238
## 76 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
#11 levels

T2krillslopes <- T2krillslopes[order(T2krillslopes$Time),]

T2.70.start <- head(T2krillslopes$Time,1)
T2.70.stop <- tail(T2krillslopes70$Time,1)
T2.70_duration <- as.numeric(T2.70.stop - T2.70.start, units = "mins")
T2.70_duration
## [1] 141.4
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ' ' ' ' 'TRIAL 03 ' ' ' ' ' ' '
# T3krillslopes <- filter(krillslopes, TrialID.x == "Trial03")
head(T3krillslopes$Time)
## [1] "2019-10-29 14:06:22 UTC" "2019-10-29 14:06:23 UTC"
## [3] "2019-10-29 14:06:24 UTC" "2019-10-29 14:06:25 UTC"
## [5] "2019-10-29 14:06:32 UTC" "2019-10-29 14:06:33 UTC"
#[1] "2019-10-29 14:06:22 UTC"

T3krillslopes70time <- filter(T3krillslopes, percentDO <=.7)
head(T3krillslopes70time$Time,1)
## [1] "2019-10-29 16:17:06 UTC"
#[1] "2019-10-29 16:17:07 UTC" 
T3krillslopes70 <- filter(T3krillslopes, Time <= as.POSIXct("2019-10-29 16:17:07", tz = "UTC"))

unique(T3krillslopes70$KrillID)
##  [1] Trial03_KRLr3_39 Trial03_KRLr3_40 Trial03_KRLr3_41 Trial03_KRLr3_42
##  [5] Trial03_KRLr3_43 Trial03_KRLr3_44 Trial03_KRLr3_45 Trial03_KRLr3_46
##  [9] Trial03_KRLr3_47 Trial03_KRLr3_48 Trial03_KRLr3_49 Trial03_KRLr3_50
## [13] Trial03_KRLr3_51 Trial03_KRLr3_52 Trial03_KRLr3_53 Trial03_KRLr3_54
## [17] Trial03_KRLr3_55 Trial03_KRLr3_56 Trial03_KRLr3_57
## 76 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
# 19 levels


T3krillslopes <- T3krillslopes[order(T3krillslopes$Time),]

T3.70.start <- head(T3krillslopes$Time,1)
T3.70.stop <- tail(T3krillslopes70$Time,1)
T3.70_duration <- as.numeric(T3.70.stop - T3.70.start, units = "mins")
T3.70_duration
## [1] 130.75
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ' ' ' ' 'TRIAL 04 ' ' ' ' ' ' '
# T4krillslopes <- filter
head(T4krillslopes$Time)
## [1] "2019-10-29 17:20:22 UTC" "2019-10-29 17:20:23 UTC"
## [3] "2019-10-29 17:20:24 UTC" "2019-10-29 17:20:25 UTC"
## [5] "2019-10-29 17:20:30 UTC" "2019-10-29 17:20:31 UTC"
#[1] "2019-10-29 17:20:22 UTC"

T4krillslopes70time <- filter(T4krillslopes, percentDO <=.7)
head(T4krillslopes70time$Time,1)
## POSIXct of length 0
#[1] POSIXct of length 0
T4krillslopes70 <- T4krillslopes


unique(T4krillslopes70$KrillID)
##  [1] Trial04_KRLr4_58 Trial04_KRLr4_59 Trial04_KRLr4_60 Trial04_KRLr4_61
##  [5] Trial04_KRLr4_62 Trial04_KRLr4_63 Trial04_KRLr4_64 Trial04_KRLr4_65
##  [9] Trial04_KRLr4_66 Trial04_KRLr4_67 Trial04_KRLr4_68 Trial04_KRLr4_69
## [13] Trial04_KRLr4_70 Trial04_KRLr4_71 Trial04_KRLr4_72 Trial04_KRLr4_73
## [17] Trial04_KRLr4_74 Trial04_KRLr4_75 Trial04_KRLr4_76
## 76 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
# 
# T4krillslopes <- T4krillslopes[order(T4krillslopes$Time),]
T4krillslopes70 <- T4krillslopes70[order(T4krillslopes70$Time),]

T4.70.start <- head(T4krillslopes70$Time,1)

T4.70.start
## [1] "2019-10-29 17:20:22 UTC"
T4.70.stop <- tail(T4krillslopes70$Time,1)
T4.70.stop
## [1] "2019-10-29 19:32:01 UTC"
T4.70_duration <- as.numeric(T4.70.stop - T4.70.start, units = "mins")
T4.70_duration
## [1] 131.65

8.8) bringing all trials back together following 70% DO selection)

krillslopes70 <- rbind(T1krillslopes70, T2krillslopes70, T3krillslopes70, T4krillslopes70)

unique(krillslopes70$KrillID)
##  [1] Trial01_KrilLR11 Trial01_KrilLR12 Trial01_KrilLR13 Trial01_KrilLR14
##  [5] Trial01_KrilLR15 Trial01_KrilLR16 Trial01_KrilLR17 Trial01_KrilLR18
##  [9] Trial01_KrilLR19 Trial01_KrILR110 Trial01_KriLR111 Trial01_KriLR112
## [13] Trial01_KriLR113 Trial01_KriLR114 Trial01_KriLR115 Trial01_KriLR116
## [17] Trial01_KriLR117 Trial01_KriLR118 Trial01_KriLR119 Trial02_KriLR220
## [21] Trial02_KriLR221 Trial02_KriLR222 Trial02_KriLR223 Trial02_KriLR224
## [25] Trial02_KriLR225 Trial02_KriLR226 Trial02_KriLR227 Trial02_KriLR228
## [29] Trial02_KriLR229 Trial02_KriLR230 Trial02_KriLR231 Trial02_KriLR232
## [33] Trial02_KriLR233 Trial02_KriLR234 Trial02_KriLR235 Trial02_KriLR236
## [37] Trial02_KriLR237 Trial02_KriLR238 Trial03_KRLr3_39 Trial03_KRLr3_40
## [41] Trial03_KRLr3_41 Trial03_KRLr3_42 Trial03_KRLr3_43 Trial03_KRLr3_44
## [45] Trial03_KRLr3_45 Trial03_KRLr3_46 Trial03_KRLr3_47 Trial03_KRLr3_48
## [49] Trial03_KRLr3_49 Trial03_KRLr3_50 Trial03_KRLr3_51 Trial03_KRLr3_52
## [53] Trial03_KRLr3_53 Trial03_KRLr3_54 Trial03_KRLr3_55 Trial03_KRLr3_56
## [57] Trial03_KRLr3_57 Trial04_KRLr4_58 Trial04_KRLr4_59 Trial04_KRLr4_60
## [61] Trial04_KRLr4_61 Trial04_KRLr4_62 Trial04_KRLr4_63 Trial04_KRLr4_64
## [65] Trial04_KRLr4_65 Trial04_KRLr4_66 Trial04_KRLr4_67 Trial04_KRLr4_68
## [69] Trial04_KRLr4_69 Trial04_KRLr4_70 Trial04_KRLr4_71 Trial04_KRLr4_72
## [73] Trial04_KRLr4_73 Trial04_KRLr4_74 Trial04_KRLr4_75 Trial04_KRLr4_76
## 76 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76

8.9) Filtering krillslopes to give each Trial only 1hr

# ' ' ' ' 'TRIAL 01 ' ' ' ' ' ' ' 
# T1krillslopes <- filter(krillslopes, TrialID.x == "Trial01")

head(T1krillslopes$Time)
## [1] "2019-10-28 14:25:01 UTC" "2019-10-28 14:25:02 UTC"
## [3] "2019-10-28 14:25:03 UTC" "2019-10-28 14:25:53 UTC"
## [5] "2019-10-28 14:25:54 UTC" "2019-10-28 14:25:55 UTC"
T1krillslopes <- T1krillslopes[order(T1krillslopes$Time),]
head(T1krillslopes$Time,1)
## [1] "2019-10-28 14:25:01 UTC"
# T1krillslopes[order(T1krillslopes$Time),]

#[1] "2019-10-28 14:25:01 UTC"

T1krillslopes1hr <- filter(T1krillslopes, T1krillslopes$Time <= as.POSIXct("2019-10-28 15:25:01", tz = "UTC"))

T1.1hr.start <- head(T1krillslopes$Time,1)
T1.1hr.stop <- tail(T1krillslopes1hr$Time,1)
T1.1hr_duration <- as.numeric(T1.1hr.stop - T1.1hr.start, units = "mins")
T1.1hr_duration
## [1] 57.7
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ' ' ' ' 'TRIAL 02 ' ' ' ' ' ' '
# T2krillslopes <- filter(krillslopes, TrialID.x == "Trial02")
head(T2krillslopes$Time)
## [1] "2019-10-28 18:55:21 UTC" "2019-10-28 18:55:22 UTC"
## [3] "2019-10-28 18:55:23 UTC" "2019-10-28 18:55:24 UTC"
## [5] "2019-10-28 18:55:33 UTC" "2019-10-28 18:55:34 UTC"
#[1] "2019-10-28 18:55:21 UTC"

T2krillslopes1hr <- filter(T2krillslopes, T2krillslopes$Time <= as.POSIXct("2019-10-28 19:55:01", tz = "UTC"))

T2.1hr.start <- head(T2krillslopes$Time,1)
T2.1hr.stop <- tail(T2krillslopes1hr$Time,1)
T2.1hr_duration <- as.numeric(T2.1hr.stop - T2.1hr.start, units = "mins")
T2.1hr_duration
## [1] 51.36667
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ' ' ' ' 'TRIAL 03 ' ' ' ' ' ' '
# T3krillslopes <- filter(krillslopes, TrialID.x == "Trial03")
head(T3krillslopes$Time)
## [1] "2019-10-29 14:06:22 UTC" "2019-10-29 14:06:23 UTC"
## [3] "2019-10-29 14:06:24 UTC" "2019-10-29 14:06:25 UTC"
## [5] "2019-10-29 14:06:32 UTC" "2019-10-29 14:06:33 UTC"
#[1] "2019-10-29 14:06:22 UTC"

T3krillslopes1hr <- filter(T3krillslopes, T3krillslopes$Time <= as.POSIXct("2019-10-29 15:06:22", tz = "UTC"))

T3.1hr.start <- head(T3krillslopes$Time,1)
T3.1hr.stop <- tail(T3krillslopes1hr$Time,1)
T3.1hr_duration <- as.numeric(T3.1hr.stop - T3.1hr.start, units = "mins")
T3.1hr_duration
## [1] 57.38333
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ' ' ' ' 'TRIAL 04 ' ' ' ' ' ' '
# T4krillslopes <- filter
T4krillslopes <- T4krillslopes[order(T4krillslopes$Time),]
head(T4krillslopes$Time, 1)
## [1] "2019-10-29 17:20:22 UTC"
#[1] "2019-10-29 17:20:22 UTC"


T4krillslopes1hr <- filter(T4krillslopes, T4krillslopes$Time <= as.POSIXct("2019-10-29 18:20:22", tz = "UTC"))


T4.1hr.start <- head(T4krillslopes$Time,1)
T4.1hr.stop <- tail(T4krillslopes1hr$Time,1)
T4.1hr.stop
## [1] "2019-10-29 18:17:41 UTC"
T4.1hr_duration <- as.numeric(T4.1hr.stop - T4.1hr.start, units = "mins")
T4.1hr_duration
## [1] 57.31667

8.10) bringing all trials back together following the 1hr selection)

krillslopes1hr <- rbind(T1krillslopes1hr, T2krillslopes1hr, T3krillslopes1hr, T4krillslopes1hr)
# ' ' ' ' 'TRIAL 01 ' ' ' ' ' ' ' 
# 
T1krillslopes <- T1krillslopes[order(T1krillslopes$Time),]
T1.dtotal.start <- head(T1krillslopes$Time,1)
T1.dtotal.stop <- tail(T1krillslopes$Time,1)
T1.dtotal_duration <- as.numeric(T1.dtotal.start - T1.dtotal.stop, units = "mins")
T1.dtotal_duration <- abs(T1.dtotal_duration)

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ' ' ' ' 'TRIAL 02 ' ' ' ' ' ' '
T2krillslopes <- T2krillslopes[order(T2krillslopes$Time),]
T2.dtotal.start <- head(T2krillslopes$Time,1)
T2.dtotal.stop <- tail(T2krillslopes$Time,1)
T2.dtotal_duration <- as.numeric(T2.dtotal.start - T2.dtotal.stop, units = "mins")
T2.dtotal_duration <- abs(T2.dtotal_duration)

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ' ' ' ' 'TRIAL 03 ' ' ' ' ' ' '
T3krillslopes <- T3krillslopes[order(T3krillslopes$Time),]
T3.dtotal.start <- head(T3krillslopes$Time,1)
T3.dtotal.stop <- tail(T3krillslopes$Time,1)
T3.dtotal_duration <- as.numeric(T3.dtotal.start - T3.dtotal.stop, units = "mins")
T3.dtotal_duration <- abs(T3.dtotal_duration)

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ' ' ' ' 'TRIAL 04 ' ' ' ' ' ' '
T4krillslopes <- T4krillslopes[order(T4krillslopes$Time),]
T4.dtotal.start <- head(T4krillslopes$Time,1)
T4.dtotal.stop <- tail(T4krillslopes$Time,1)
T4.dtotal_duration <- as.numeric(T4.dtotal.start - T4.dtotal.stop, units = "mins")
T4.dtotal_duration <- abs(T4.dtotal_duration)

9.) Respirometry Table

RESPgrp <- c("DayOne_TrialOne", "DayOne_TrialTwo", "DayTwo_TrialOne", "DayTwo_TrialTwo")

RESPdf <- c("allpoints_dtotal", "80%_DO_R.censored", "70%_DO_R.censored", "1hr_R.censored")

Trial1_duration <- c((T1.dtotal_duration),  
                     (T1.80_duration), 
                     (T1.70_duration), 
                     (T1.1hr_duration))

Trial2_duration <- c((T2.dtotal_duration),  
                     (T2.80_duration), 
                     (T2.70_duration), 
                     (T2.1hr_duration))

Trial3_duration <- c((T3.dtotal_duration),  
                     (T3.80_duration), 
                     (T3.70_duration), 
                     (T3.1hr_duration))

Trial4_duration <- c((T4.dtotal_duration),  
                     (T4.80_duration), 
                     (T4.70_duration), 
                     (T4.1hr_duration))

RespirometryTrialTable <- data.frame(RESPdf, 
                                    Trial1_duration, 
                                    Trial2_duration, 
                                    Trial3_duration, 
                                    Trial4_duration)

write.csv(RespirometryTrialTable, "2021.01.20_RespirometryTrialTable.csv")


# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# ## All points 
# T1.allpts.start <- head(T1krillslopes$Time,1)
# T1.allpts.stop <- tail(T1krillslopes$Time,1)
# 
# RespirometryTrial_d1.allpts.start <- T1.allpts.start 
# 
# T2.allpts.start <- head(T2krillslopes$Time,1)
# T2.allpts.stop <- tail(T2krillslopes$Time,1)
# 
# T3.allpts.start <- head(T3krillslopes$Time,1)
# T3.allpts.stop <- tail(T3krillslopes$Time,1)
# 
# T4.allpts.start <- head(T4krillslopes$Time,1)
# T4.allpts.stop <- tail(T4krillslopes$Time,1)
# 
# RespirometryTrial_d1.allpts.stop <- T2.allpts.stop 
# 
# RespirometryTrial_d2.allpts.start <- T3.allpts.start 
# RespirometryTrial_d2.allpts.stop <- T4.allpts.stop 

13.) Investigating Outliers

The krillslopes dataframe is broken up into four different dataframes based on Trial ID. These dataframes will be further filtered to remove the Ambient Treatment. Some rounds of respirometry featured a greater number ambient treatment animals and should account for the differences in number of observations between dataframes.

13.1 Investigating Outliers by Trial- cleaning up Trials Removing AMB from the 80% Threshold

# Filtering down krillslopes to Trial 01, 02, 03 & 04 with only included treatments
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ''' Trial 01 ''' 
T1krillslopes <- droplevels(filter(T1krillslopes, Treatment != "AMB"))
levels(T1krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
T1krillslopes80 <- droplevels(filter(T1krillslopes80, Treatment != "AMB"))
levels(T1krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |  

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ''' Trial 02 '''
T2krillslopes <- droplevels(filter(T2krillslopes, Treatment != "AMB"))
levels(T2krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a"
T2krillslopes80 <- droplevels(filter(T2krillslopes80, Treatment != "AMB"))
levels(T2krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ''' Trial 03 '''
T3krillslopes <- droplevels(filter(T3krillslopes, Treatment != "AMB"))
levels(T3krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
T3krillslopes80 <- droplevels(filter(T3krillslopes80, Treatment != "AMB"))
levels(T3krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ''' Trial 04 '''
T4krillslopes <- droplevels(filter(T4krillslopes, Treatment != "AMB"))
levels(T4krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a"
T4krillslopes80 <- droplevels(filter(T4krillslopes80, Treatment != "AMB"))
levels(T4krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

13.1a Investigating Outliers by Trial- cleaning up Trials Removing AMB from the 70% Threshold

# Filtering down krillslopes to Trial 01, 02, 03 & 04 with only included treatments
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ''' Trial 01 ''' 
T1krillslopes <- droplevels(filter(T1krillslopes, Treatment != "AMB"))
levels(T1krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
T1krillslopes70 <- droplevels(filter(T1krillslopes70, Treatment != "AMB"))
levels(T1krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |  

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ''' Trial 02 '''
T2krillslopes <- droplevels(filter(T2krillslopes, Treatment != "AMB"))
levels(T2krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a"
T2krillslopes70 <- droplevels(filter(T2krillslopes70, Treatment != "AMB"))
levels(T2krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ''' Trial 03 '''
T3krillslopes <- droplevels(filter(T3krillslopes, Treatment != "AMB"))
levels(T3krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
T3krillslopes70 <- droplevels(filter(T3krillslopes70, Treatment != "AMB"))
levels(T3krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ''' Trial 04 '''
T4krillslopes <- droplevels(filter(T4krillslopes, Treatment != "AMB"))
levels(T4krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a"
T4krillslopes70 <- droplevels(filter(T4krillslopes70, Treatment != "AMB"))
levels(T4krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

13.1a Investigating Outliers by Trial- cleaning up Trials Removing AMB from the 1hr Threshold

# Filtering down krillslopes to Trial 01, 02, 03 & 04 with only included treatments
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ''' Trial 01 ''' 
T1krillslopes <- droplevels(filter(T1krillslopes, Treatment != "AMB"))
levels(T1krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
T1krillslopes1hr <- droplevels(filter(T1krillslopes1hr, Treatment != "AMB"))
levels(T1krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |  

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ''' Trial 02 '''
T2krillslopes <- droplevels(filter(T2krillslopes, Treatment != "AMB"))
levels(T2krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a"
T2krillslopes1hr <- droplevels(filter(T2krillslopes1hr, Treatment != "AMB"))
levels(T2krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ''' Trial 03 '''
T3krillslopes <- droplevels(filter(T3krillslopes, Treatment != "AMB"))
levels(T3krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
T3krillslopes1hr <- droplevels(filter(T3krillslopes1hr, Treatment != "AMB"))
levels(T3krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# ''' Trial 04 '''
T4krillslopes <- droplevels(filter(T4krillslopes, Treatment != "AMB"))
levels(T4krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a"
T4krillslopes1hr <- droplevels(filter(T4krillslopes1hr, Treatment != "AMB"))
levels(T4krillslopes$Treatment)
## [1] "CHG" "CUR" "n/a"
# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

Time Series Plot for the unfiltered Krill Slopes Dataframe ###13.1a.1 Investigating Outliers by Trial- timeseries plots showing the four distinct dataframes

par(mfrow = c(2,2))
plot(T1krillslopes$delta_t, T1krillslopes$oxygen)
plot(T2krillslopes$delta_t, T2krillslopes$oxygen)
plot(T3krillslopes$delta_t, T3krillslopes$oxygen)
plot(T4krillslopes$delta_t, T4krillslopes$oxygen)

Time Series Plot for Krill selected before 1st vial reached 80% DO ###13.1b Investigating Outliers by Trial- timeseries plots showing the four distinct dataframes

par(mfrow = c(2,2))
plot(T1krillslopes80$delta_t, T1krillslopes80$oxygen)
plot(T2krillslopes80$delta_t, T2krillslopes80$oxygen)
plot(T3krillslopes80$delta_t, T3krillslopes80$oxygen)
plot(T4krillslopes80$delta_t, T4krillslopes80$oxygen)

Time Series Plot for Krill selected before 1st vial reached 70% DO ###13.1c Investigating Outliers by Trial- timeseries plots showing the four distinct dataframes

par(mfrow = c(2,2))
plot(T1krillslopes70$delta_t, T1krillslopes70$oxygen)
plot(T2krillslopes70$delta_t, T2krillslopes70$oxygen)
plot(T3krillslopes70$delta_t, T3krillslopes70$oxygen)
plot(T4krillslopes70$delta_t, T4krillslopes70$oxygen)

Time Series Plot for Krill selected (1hour) per trial ###13.1d Investigating Outliers by Trial- timeseries plots showing the four distinct dataframes

par(mfrow = c(2,2))
plot(T1krillslopes1hr$delta_t, T1krillslopes1hr$oxygen)
plot(T2krillslopes1hr$delta_t, T2krillslopes1hr$oxygen)
plot(T3krillslopes1hr$delta_t, T3krillslopes1hr$oxygen)
plot(T4krillslopes1hr$delta_t, T4krillslopes1hr$oxygen)

13.e Example of loop and function writting Kate is trying to for each krill

13.2e) take 1 df at a time

# read the 1 dataframe per trial
# observe it learn it's secrets
dim(T1krillslopes)
## [1] 932  77
#kable(T1krillslopes)

13.2f) Use the unique tool to get names for each krill

unique(T1krillslopes$KrillID)
##  [1] Trial01_KrilLR11 Trial01_KrilLR12 Trial01_KrilLR13 Trial01_KrilLR14
##  [5] Trial01_KrilLR15 Trial01_KrilLR16 Trial01_KrilLR17 Trial01_KrilLR18
##  [9] Trial01_KrilLR19 Trial01_KrILR110 Trial01_KriLR111 Trial01_KriLR112
## [13] Trial01_KriLR113 Trial01_KriLR114 Trial01_KriLR115 Trial01_KriLR116
## [17] Trial01_KriLR117 Trial01_KriLR118 Trial01_KriLR119
## 19 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial01_KriLR119
qT1krillslopes <- unique(T1krillslopes$KrillID)
#kable(qT1krillslopes)

13.2g) Create a linear model object for 1 krill

df_KrillR11 <- T1krillslopes[T1krillslopes$KrillID == "Trial01_KrilLR11",]
lm_KrillR11 <- lm(df_KrillR11$oxygen ~ df_KrillR11$delta_t)

13.2h) Use the fortify function to get the residuals and cook.sd for each observation

#lm_KrillR11 <- lm(df_KrillR11$oxygen ~ df_KrillR11$delta_t)
#lm_KrillR11 is the referenced linear model object
df.lm.KrillR11 <- fortify(lm_KrillR11, df_KrillR11)
#kable(df.lm.KrillR11)

13.2i) Indentify which observations have a cooksd score above 4/n

n is the whole number of observations on that krill in the vial

#df.lm.KrillR11sat$.cooksd <- df.lm.KrillR11[df.lm.KrillR11$.cooksd <= 4/(length(df.lm.KrillR11$KrillID)), ]

13.2j) Use one dataframe to sort another

df.lm.KrillR11$.cooksd <= 4/(length(df.lm.KrillR11$KrillID))
##  [1] FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE
## [13]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
## [25]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
## [37]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE

14.) Krill Sparkle Function (standard krillslopes dataframe)

KRILLLmSparkle <- function(dfToFilter) {
  # Determine the unique list of Krill IDs
  krillIds <- unique(dfToFilter$KrillID)
  
  # Create an empty list to hold the filtered dataframes we'll eventually combine
  filteredData <- list()
  filteredDataIndex <- 1
  
  # Loop over each Krill ID
  for (krillId in krillIds) {
    #print(krillId)
    # Split the dataframe by the Krill ID
    filteredKrillIdData <- dfToFilter[dfToFilter$KrillID == krillId,]
    #print(filteredKrillIdData)
    
    # Create the Linear Model of the resulting sub data frame
    lm_Krill <- lm(filteredKrillIdData$oxygen ~ filteredKrillIdData$delta_t)
    
    # Calculate the residuals and cook stdev scores and layer them on as columns into the filtered dataframe
    df.lm.Krill <- fortify(lm_Krill, filteredKrillIdData) 
    #print(df.lm.Krill)
    
    # Filter out measurements that are outliers based on the cook stdev value
    df.lm.Krill <- df.lm.Krill[df.lm.Krill$.cooksd <= 4/(length(df.lm.Krill$KrillID)), ]
    #print(df.lm.Krill)
    
    # Merge the filtered data back into the dataframe to return
    filteredData[[filteredDataIndex]] <- df.lm.Krill
    filteredDataIndex <- filteredDataIndex + 1
  }
  
  # Combine the list of dataframes into a single dataframe and return it
  return(do.call(rbind, filteredData))
}

# stop here and go to next unique krill ID

T1krillslopes.filtered <- KRILLLmSparkle(T1krillslopes)
T2krillslopes.filtered <- KRILLLmSparkle(T2krillslopes)
T3krillslopes.filtered <- KRILLLmSparkle(T3krillslopes)
T4krillslopes.filtered <- KRILLLmSparkle(T4krillslopes)

par(mfrow = c(2,2))
plot(T1krillslopes.filtered$delta_t, T1krillslopes.filtered$oxygen)
title("Trial 01, Outliers Excluded")
plot(T2krillslopes.filtered$delta_t, T2krillslopes.filtered$oxygen)
title("Trial 02, Outliers Excluded")
plot(T3krillslopes.filtered$delta_t, T3krillslopes.filtered$oxygen)
title("Trial 03, Outliers Excluded")
plot(T4krillslopes.filtered$delta_t, T4krillslopes.filtered$oxygen)
title("Trial 04, Outliers Excluded")

14.) Rbind back the filtered dataframes following the sparkle function

T1to4krillslopes.filtered <- rbind(T1krillslopes.filtered, 
                                   T2krillslopes.filtered, 
                                   T3krillslopes.filtered, 
                                   T4krillslopes.filtered)

15.) Krill Sparkle Function (80% DO dataframe)

KRILLLmSparkle <- function(dfToFilter) {
  # Determine the unique list of Krill IDs
  krillIds <- unique(dfToFilter$KrillID)
  
  # Create an empty list to hold the filtered dataframes we'll eventually combine
  filteredData <- list()
  filteredDataIndex <- 1
  
  # Loop over each Krill ID
  for (krillId in krillIds) {
    #print(krillId)
    # Split the dataframe by the Krill ID
    filteredKrillIdData <- dfToFilter[dfToFilter$KrillID == krillId,]
    #print(filteredKrillIdData)
    
    # Create the Linear Model of the resulting sub data frame
    lm_Krill <- lm(filteredKrillIdData$oxygen ~ filteredKrillIdData$delta_t)
    
    # Calculate the residuals and cook stdev scores and layer them on as columns into the filtered dataframe
    df.lm.Krill <- fortify(lm_Krill, filteredKrillIdData) 
    #print(df.lm.Krill)
    
    # Filter out measurements that are outliers based on the cook stdev value
    df.lm.Krill <- df.lm.Krill[df.lm.Krill$.cooksd <= 4/(length(df.lm.Krill$KrillID)), ]
    #print(df.lm.Krill)
    
    # Merge the filtered data back into the dataframe to return
    filteredData[[filteredDataIndex]] <- df.lm.Krill
    filteredDataIndex <- filteredDataIndex + 1
  }
  
  # Combine the list of dataframes into a single dataframe and return it
  return(do.call(rbind, filteredData))
}

# stop here and go to next unique krill ID

T1krillslopes80.filtered <- KRILLLmSparkle(T1krillslopes80)
T2krillslopes80.filtered <- KRILLLmSparkle(T2krillslopes80)
T3krillslopes80.filtered <- KRILLLmSparkle(T3krillslopes80)
T4krillslopes80.filtered <- KRILLLmSparkle(T4krillslopes80)

par(mfrow = c(2,2))
plot(T1krillslopes80.filtered$delta_t, T1krillslopes80.filtered$oxygen)
title("Trial 01 80% DO Filter Applied, Outliers Excluded")
plot(T2krillslopes80.filtered$delta_t, T2krillslopes80.filtered$oxygen)
title("Trial 02 80% DO Filter Applied, Outliers Excluded")
plot(T3krillslopes80.filtered$delta_t, T3krillslopes80.filtered$oxygen)
title("Trial 03 80% DO Filter Applied, Outliers Excluded")
plot(T4krillslopes80.filtered$delta_t, T4krillslopes80.filtered$oxygen)
title("Trial 04 80% DO Filter Applied, Outliers Excluded")

15.a) Krill Sparkle Function (70% DO dataframe)

KRILLLmSparkle <- function(dfToFilter) {
  # Determine the unique list of Krill IDs
  krillIds <- unique(dfToFilter$KrillID)
  
  # Create an empty list to hold the filtered dataframes we'll eventually combine
  filteredData <- list()
  filteredDataIndex <- 1
  
  # Loop over each Krill ID
  for (krillId in krillIds) {
    #print(krillId)
    # Split the dataframe by the Krill ID
    filteredKrillIdData <- dfToFilter[dfToFilter$KrillID == krillId,]
    #print(filteredKrillIdData)
    
    # Create the Linear Model of the resulting sub data frame
    lm_Krill <- lm(filteredKrillIdData$oxygen ~ filteredKrillIdData$delta_t)
    
    # Calculate the residuals and cook stdev scores and layer them on as columns into the filtered dataframe
    df.lm.Krill <- fortify(lm_Krill, filteredKrillIdData) 
    #print(df.lm.Krill)
    
    # Filter out measurements that are outliers based on the cook stdev value
    df.lm.Krill <- df.lm.Krill[df.lm.Krill$.cooksd <= 4/(length(df.lm.Krill$KrillID)), ]
    #print(df.lm.Krill)
    
    # Merge the filtered data back into the dataframe to return
    filteredData[[filteredDataIndex]] <- df.lm.Krill
    filteredDataIndex <- filteredDataIndex + 1
  }
  
  # Combine the list of dataframes into a single dataframe and return it
  return(do.call(rbind, filteredData))
}

# stop here and go to next unique krill ID

T1krillslopes70.filtered <- KRILLLmSparkle(T1krillslopes70)
T2krillslopes70.filtered <- KRILLLmSparkle(T2krillslopes70)
T3krillslopes70.filtered <- KRILLLmSparkle(T3krillslopes70)
T4krillslopes70.filtered <- KRILLLmSparkle(T4krillslopes70)

par(mfrow = c(2,2))
plot(T1krillslopes70.filtered$delta_t, T1krillslopes70.filtered$oxygen)
title("Trial 01 70% DO Filter Applied, Outliers Excluded")
plot(T2krillslopes70.filtered$delta_t, T2krillslopes70.filtered$oxygen)
title("Trial 02 70% DO Filter Applied, Outliers Excluded")
plot(T3krillslopes70.filtered$delta_t, T3krillslopes70.filtered$oxygen)
title("Trial 03 70% DO Filter Applied, Outliers Excluded")
plot(T4krillslopes70.filtered$delta_t, T4krillslopes70.filtered$oxygen)
title("Trial 04 80% DO Filter Applied, Outliers Excluded")

15.b) Krill Sparkle Function (1hr Trial dataframe)

KRILLLmSparkle <- function(dfToFilter) {
  # Determine the unique list of Krill IDs
  krillIds <- unique(dfToFilter$KrillID)
  
  # Create an empty list to hold the filtered dataframes we'll eventually combine
  filteredData <- list()
  filteredDataIndex <- 1
  
  # Loop over each Krill ID
  for (krillId in krillIds) {
    #print(krillId)
    # Split the dataframe by the Krill ID
    filteredKrillIdData <- dfToFilter[dfToFilter$KrillID == krillId,]
    #print(filteredKrillIdData)
    
    # Create the Linear Model of the resulting sub data frame
    lm_Krill <- lm(filteredKrillIdData$oxygen ~ filteredKrillIdData$delta_t)
    
    # Calculate the residuals and cook stdev scores and layer them on as columns into the filtered dataframe
    df.lm.Krill <- fortify(lm_Krill, filteredKrillIdData) 
    #print(df.lm.Krill)
    
    # Filter out measurements that are outliers based on the cook stdev value
    df.lm.Krill <- df.lm.Krill[df.lm.Krill$.cooksd <= 4/(length(df.lm.Krill$KrillID)), ]
    #print(df.lm.Krill)
    
    # Merge the filtered data back into the dataframe to return
    filteredData[[filteredDataIndex]] <- df.lm.Krill
    filteredDataIndex <- filteredDataIndex + 1
  }
  
  # Combine the list of dataframes into a single dataframe and return it
  return(do.call(rbind, filteredData))
}

# stop here and go to next unique krill ID

T1krillslopes1hr.filtered <- KRILLLmSparkle(T1krillslopes1hr)
T2krillslopes1hr.filtered <- KRILLLmSparkle(T2krillslopes1hr)
T3krillslopes1hr.filtered <- KRILLLmSparkle(T3krillslopes1hr)
T4krillslopes1hr.filtered <- KRILLLmSparkle(T4krillslopes1hr)

par(mfrow = c(2,2))
plot(T1krillslopes1hr.filtered$delta_t, T1krillslopes1hr.filtered$oxygen)
title("Trial 01 1hr Filter Applied, Outliers Excluded")
plot(T2krillslopes1hr.filtered$delta_t, T2krillslopes1hr.filtered$oxygen)
title("Trial 02 1hr Filter Applied, Outliers Excluded")
plot(T3krillslopes1hr.filtered$delta_t, T3krillslopes1hr.filtered$oxygen)
title("Trial 03 1hr Filter Applied, Outliers Excluded")
plot(T4krillslopes1hr.filtered$delta_t, T4krillslopes1hr.filtered$oxygen)
title("Trial 04 1hr Filter Applied, Outliers Excluded")

15.d Bringing all trials back together 80%, 70% and 1hr

krillslopes80.filtered <- rbind(T1krillslopes80.filtered, 
                                T2krillslopes80.filtered, 
                                T3krillslopes80.filtered, 
                                T4krillslopes80.filtered)

unique(krillslopes80.filtered$KrillID)
##  [1] Trial01_KrilLR11 Trial01_KrilLR12 Trial01_KrilLR13 Trial01_KrilLR14
##  [5] Trial01_KrilLR15 Trial01_KrilLR16 Trial01_KrilLR17 Trial01_KrilLR18
##  [9] Trial01_KrilLR19 Trial01_KrILR110 Trial01_KriLR111 Trial01_KriLR112
## [13] Trial01_KriLR113 Trial01_KriLR114 Trial01_KriLR115 Trial01_KriLR116
## [17] Trial01_KriLR117 Trial01_KriLR118 Trial01_KriLR119 Trial02_KriLR220
## [21] Trial02_KriLR223 Trial02_KriLR224 Trial02_KriLR226 Trial02_KriLR227
## [25] Trial02_KriLR229 Trial02_KriLR230 Trial02_KriLR232 Trial02_KriLR233
## [29] Trial02_KriLR234 Trial02_KriLR235 Trial03_KRLr3_39 Trial03_KRLr3_40
## [33] Trial03_KRLr3_41 Trial03_KRLr3_42 Trial03_KRLr3_43 Trial03_KRLr3_44
## [37] Trial03_KRLr3_45 Trial03_KRLr3_46 Trial03_KRLr3_47 Trial03_KRLr3_48
## [41] Trial03_KRLr3_49 Trial03_KRLr3_50 Trial03_KRLr3_51 Trial03_KRLr3_52
## [45] Trial03_KRLr3_53 Trial03_KRLr3_54 Trial03_KRLr3_55 Trial03_KRLr3_56
## [49] Trial03_KRLr3_57 Trial04_KRLr4_58 Trial04_KRLr4_59 Trial04_KRLr4_62
## [53] Trial04_KRLr4_65 Trial04_KRLr4_67 Trial04_KRLr4_68 Trial04_KRLr4_69
## [57] Trial04_KRLr4_70 Trial04_KRLr4_71 Trial04_KRLr4_75 Trial04_KRLr4_76
## 60 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
krillslopes70.filtered <- rbind(T1krillslopes70.filtered, 
                                T2krillslopes70.filtered, 
                                T3krillslopes70.filtered, 
                                T4krillslopes70.filtered)

unique(krillslopes70.filtered$KrillID)
##  [1] Trial01_KrilLR11 Trial01_KrilLR12 Trial01_KrilLR13 Trial01_KrilLR14
##  [5] Trial01_KrilLR15 Trial01_KrilLR16 Trial01_KrilLR17 Trial01_KrilLR18
##  [9] Trial01_KrilLR19 Trial01_KrILR110 Trial01_KriLR111 Trial01_KriLR112
## [13] Trial01_KriLR113 Trial01_KriLR114 Trial01_KriLR115 Trial01_KriLR116
## [17] Trial01_KriLR117 Trial01_KriLR118 Trial01_KriLR119 Trial02_KriLR220
## [21] Trial02_KriLR223 Trial02_KriLR224 Trial02_KriLR226 Trial02_KriLR227
## [25] Trial02_KriLR229 Trial02_KriLR230 Trial02_KriLR232 Trial02_KriLR233
## [29] Trial02_KriLR234 Trial02_KriLR235 Trial03_KRLr3_39 Trial03_KRLr3_40
## [33] Trial03_KRLr3_41 Trial03_KRLr3_42 Trial03_KRLr3_43 Trial03_KRLr3_44
## [37] Trial03_KRLr3_45 Trial03_KRLr3_46 Trial03_KRLr3_47 Trial03_KRLr3_48
## [41] Trial03_KRLr3_49 Trial03_KRLr3_50 Trial03_KRLr3_51 Trial03_KRLr3_52
## [45] Trial03_KRLr3_53 Trial03_KRLr3_54 Trial03_KRLr3_55 Trial03_KRLr3_56
## [49] Trial03_KRLr3_57 Trial04_KRLr4_58 Trial04_KRLr4_59 Trial04_KRLr4_62
## [53] Trial04_KRLr4_65 Trial04_KRLr4_67 Trial04_KRLr4_68 Trial04_KRLr4_69
## [57] Trial04_KRLr4_70 Trial04_KRLr4_71 Trial04_KRLr4_75 Trial04_KRLr4_76
## 60 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
krillslopes1hr.filtered <- rbind(T1krillslopes1hr.filtered, 
                                T2krillslopes1hr.filtered, 
                                T3krillslopes1hr.filtered, 
                                T4krillslopes1hr.filtered)

unique(krillslopes1hr.filtered$KrillID)
##  [1] Trial01_KrilLR11 Trial01_KrilLR12 Trial01_KrilLR13 Trial01_KrilLR14
##  [5] Trial01_KrilLR15 Trial01_KrilLR16 Trial01_KrilLR17 Trial01_KrilLR18
##  [9] Trial01_KrilLR19 Trial01_KrILR110 Trial01_KriLR111 Trial01_KriLR112
## [13] Trial01_KriLR113 Trial01_KriLR114 Trial01_KriLR115 Trial01_KriLR116
## [17] Trial01_KriLR117 Trial01_KriLR118 Trial01_KriLR119 Trial02_KriLR220
## [21] Trial02_KriLR223 Trial02_KriLR224 Trial02_KriLR226 Trial02_KriLR227
## [25] Trial02_KriLR229 Trial02_KriLR230 Trial02_KriLR232 Trial02_KriLR233
## [29] Trial02_KriLR234 Trial02_KriLR235 Trial03_KRLr3_39 Trial03_KRLr3_40
## [33] Trial03_KRLr3_41 Trial03_KRLr3_42 Trial03_KRLr3_43 Trial03_KRLr3_44
## [37] Trial03_KRLr3_45 Trial03_KRLr3_46 Trial03_KRLr3_47 Trial03_KRLr3_48
## [41] Trial03_KRLr3_49 Trial03_KRLr3_50 Trial03_KRLr3_51 Trial03_KRLr3_52
## [45] Trial03_KRLr3_53 Trial03_KRLr3_54 Trial03_KRLr3_55 Trial03_KRLr3_56
## [49] Trial03_KRLr3_57 Trial04_KRLr4_58 Trial04_KRLr4_59 Trial04_KRLr4_62
## [53] Trial04_KRLr4_65 Trial04_KRLr4_67 Trial04_KRLr4_68 Trial04_KRLr4_69
## [57] Trial04_KRLr4_70 Trial04_KRLr4_71 Trial04_KRLr4_75 Trial04_KRLr4_76
## 60 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76

16.) Plots Following Filtering

16.1a) Trial 1 Vial Oxygen over Time

# T1dTotal original 
# T1dTotal.filtered outliers removed 

#patchwork

orip1 <- ggplot(T1krillslopes, aes(x = Time, y = oxygen, colour = Treatment)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial01 Vial Oxygen, with Outliers") +
  #geom_hline(yintercept = c(.8), colour = "red") +
  facet_wrap(~ Treatment) + 
  theme_bw()


orip2 <- ggplot(T2krillslopes, aes(x = Time, y = oxygen, colour = Treatment)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial02 Vial Oxygen, with Outliers") +
  #geom_hline(yintercept = c(.8), colour = "red") +
  facet_wrap(~ Treatment) + 
  theme_bw()

orip3 <- ggplot(T3krillslopes, aes(x = Time, y = oxygen, colour = Treatment)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial03 Vial Oxygen, with Outliers") +
  #geom_hline(yintercept = c(.8), colour = "red") +
  facet_wrap(~ Treatment) + 
  theme_bw()


orip4 <- ggplot(T4krillslopes, aes(x = Time, y = oxygen, colour = Treatment)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial04 Vial Oxygen, with Outliers") +
  #geom_hline(yintercept = c(.8), colour = "red") +
  facet_wrap(~ Treatment) + 
  theme_bw()


# T1krillslopes.filtered outliers removed 


filtp1 <- ggplot(T1krillslopes.filtered, aes(x = Time, y = oxygen, colour = Treatment)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial01 Vial Oxygen, Outliers Filtered") +
  #geom_hline(yintercept = c(.8), colour = "red") +
  facet_wrap(~ Treatment) + 
  theme_bw()


filtp2 <- ggplot(T2krillslopes.filtered, aes(x = Time, y = oxygen, colour = Treatment)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial02 Vial Oxygen, Outliers Filtered") +
  #geom_hline(yintercept = c(.8), colour = "red") +
  facet_wrap(~ Treatment) + 
  theme_bw()

filtp3 <- ggplot(T3krillslopes.filtered, aes(x = Time, y = oxygen, colour = Treatment)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial03 Vial Oxygen, Outliers Filtered") +
  #geom_hline(yintercept = c(.8), colour = "red") +
  facet_wrap(~ Treatment) + 
  theme_bw()


filtp4 <- ggplot(T4krillslopes.filtered, aes(x = Time, y = oxygen, colour = Treatment)) +
  geom_point(size = 1) +
  geom_smooth(method = "lm") +
  #scale_y_continuous(breaks=seq(250,950,by=50))   +
  ggtitle("Trial04 Vial Oxygen, Outliers Filtered") +
  #geom_hline(yintercept = c(.8), colour = "red") +
  facet_wrap(~ Treatment) + 
  theme_bw()


(orip1|filtp1)
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'

# ((p1|p2)/(p3|p4))|guide_area()+plot_layout(guides = "collect", rel_width=c(4,1))

#((p1|p2)/(p3|p4))|guide_area()+plot_layout(guides = "collect", widths =c(4,1))

#((p1|p2)/(p3|p4))|guide_area()+plot_layout(guides = "collect", widths = c(10, 10, 5))

#(p1|p2)/(p3|p4) + plot_layout(guides= "collect") &  theme(text = element_text(size = 10))


#guide_area()

16.1b After Filtering Trial 02

(orip2|filtp2)
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'

16.1c After Filtering Trial 03

(orip3|filtp3)
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'

16.1d After Filtering Trial 04

(orip4|filtp4)
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'

(patchwork learning in this chunk ignore for now)

# (p1|p2)/(p3|p4) + 
#   plot_layout(guides= "collect")
#       guide_area() + plot_layout(guides = 'collect')


# ((p1|p2)/(p3|p4))|guide_area()+plot_layout(guides = "collect", rel_width=c(4,1))

## rel_width=c(4,1)) possible 2, 2, 1

17.x) Analysis, Respirometry - outliers removed (investigating krillslopes)

#*********************************
## 17.) Analysis, Respirometry - Creating the Slope Function  
#*********************************  

T1to4krillslopes.filtered
unique(T1to4krillslopes.filtered$KrillID)
##  [1] Trial01_KrilLR11 Trial01_KrilLR12 Trial01_KrilLR13 Trial01_KrilLR14
##  [5] Trial01_KrilLR15 Trial01_KrilLR16 Trial01_KrilLR17 Trial01_KrilLR18
##  [9] Trial01_KrilLR19 Trial01_KrILR110 Trial01_KriLR111 Trial01_KriLR112
## [13] Trial01_KriLR113 Trial01_KriLR114 Trial01_KriLR115 Trial01_KriLR116
## [17] Trial01_KriLR117 Trial01_KriLR118 Trial01_KriLR119 Trial02_KriLR220
## [21] Trial02_KriLR223 Trial02_KriLR224 Trial02_KriLR226 Trial02_KriLR227
## [25] Trial02_KriLR229 Trial02_KriLR230 Trial02_KriLR232 Trial02_KriLR233
## [29] Trial02_KriLR234 Trial02_KriLR235 Trial03_KRLr3_39 Trial03_KRLr3_40
## [33] Trial03_KRLr3_41 Trial03_KRLr3_42 Trial03_KRLr3_43 Trial03_KRLr3_44
## [37] Trial03_KRLr3_45 Trial03_KRLr3_46 Trial03_KRLr3_47 Trial03_KRLr3_48
## [41] Trial03_KRLr3_49 Trial03_KRLr3_50 Trial03_KRLr3_51 Trial03_KRLr3_52
## [45] Trial03_KRLr3_53 Trial03_KRLr3_54 Trial03_KRLr3_55 Trial03_KRLr3_56
## [49] Trial03_KRLr3_57 Trial04_KRLr4_58 Trial04_KRLr4_59 Trial04_KRLr4_62
## [53] Trial04_KRLr4_65 Trial04_KRLr4_67 Trial04_KRLr4_68 Trial04_KRLr4_69
## [57] Trial04_KRLr4_70 Trial04_KRLr4_71 Trial04_KRLr4_75 Trial04_KRLr4_76
## 60 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
# 
# levels(T1to4krillslopes.filtered$Treatment)
# T1to4krillslopes.filtered$Treatment <- as.character(T1to4krillslopes.filtered$Treatment)
# unique(T1to4krillslopes.filtered$Treatment)
# T1to4krillslopes.filtered <- as.factor(T1to4krillslopes.filtered$Treatment)

T1to4krillslopes.filtered$SensoredSlope <- ""
T1to4krillslopes.filtered$delta_t <- as.numeric(T1to4krillslopes.filtered$delta_t)


krillslopes80.filtered 
nlevels(krillslopes80.filtered$Treatment)
## [1] 4
unique(krillslopes80.filtered$KrillID)
##  [1] Trial01_KrilLR11 Trial01_KrilLR12 Trial01_KrilLR13 Trial01_KrilLR14
##  [5] Trial01_KrilLR15 Trial01_KrilLR16 Trial01_KrilLR17 Trial01_KrilLR18
##  [9] Trial01_KrilLR19 Trial01_KrILR110 Trial01_KriLR111 Trial01_KriLR112
## [13] Trial01_KriLR113 Trial01_KriLR114 Trial01_KriLR115 Trial01_KriLR116
## [17] Trial01_KriLR117 Trial01_KriLR118 Trial01_KriLR119 Trial02_KriLR220
## [21] Trial02_KriLR223 Trial02_KriLR224 Trial02_KriLR226 Trial02_KriLR227
## [25] Trial02_KriLR229 Trial02_KriLR230 Trial02_KriLR232 Trial02_KriLR233
## [29] Trial02_KriLR234 Trial02_KriLR235 Trial03_KRLr3_39 Trial03_KRLr3_40
## [33] Trial03_KRLr3_41 Trial03_KRLr3_42 Trial03_KRLr3_43 Trial03_KRLr3_44
## [37] Trial03_KRLr3_45 Trial03_KRLr3_46 Trial03_KRLr3_47 Trial03_KRLr3_48
## [41] Trial03_KRLr3_49 Trial03_KRLr3_50 Trial03_KRLr3_51 Trial03_KRLr3_52
## [45] Trial03_KRLr3_53 Trial03_KRLr3_54 Trial03_KRLr3_55 Trial03_KRLr3_56
## [49] Trial03_KRLr3_57 Trial04_KRLr4_58 Trial04_KRLr4_59 Trial04_KRLr4_62
## [53] Trial04_KRLr4_65 Trial04_KRLr4_67 Trial04_KRLr4_68 Trial04_KRLr4_69
## [57] Trial04_KRLr4_70 Trial04_KRLr4_71 Trial04_KRLr4_75 Trial04_KRLr4_76
## 60 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
krillslopes80.filtered$SensoredSlope <- ""
krillslopes80.filtered$delta_t <- as.numeric(krillslopes80.filtered$delta_t)

krillslopes70.filtered 
levels(krillslopes70.filtered$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
unique(krillslopes70.filtered$KrillID)
##  [1] Trial01_KrilLR11 Trial01_KrilLR12 Trial01_KrilLR13 Trial01_KrilLR14
##  [5] Trial01_KrilLR15 Trial01_KrilLR16 Trial01_KrilLR17 Trial01_KrilLR18
##  [9] Trial01_KrilLR19 Trial01_KrILR110 Trial01_KriLR111 Trial01_KriLR112
## [13] Trial01_KriLR113 Trial01_KriLR114 Trial01_KriLR115 Trial01_KriLR116
## [17] Trial01_KriLR117 Trial01_KriLR118 Trial01_KriLR119 Trial02_KriLR220
## [21] Trial02_KriLR223 Trial02_KriLR224 Trial02_KriLR226 Trial02_KriLR227
## [25] Trial02_KriLR229 Trial02_KriLR230 Trial02_KriLR232 Trial02_KriLR233
## [29] Trial02_KriLR234 Trial02_KriLR235 Trial03_KRLr3_39 Trial03_KRLr3_40
## [33] Trial03_KRLr3_41 Trial03_KRLr3_42 Trial03_KRLr3_43 Trial03_KRLr3_44
## [37] Trial03_KRLr3_45 Trial03_KRLr3_46 Trial03_KRLr3_47 Trial03_KRLr3_48
## [41] Trial03_KRLr3_49 Trial03_KRLr3_50 Trial03_KRLr3_51 Trial03_KRLr3_52
## [45] Trial03_KRLr3_53 Trial03_KRLr3_54 Trial03_KRLr3_55 Trial03_KRLr3_56
## [49] Trial03_KRLr3_57 Trial04_KRLr4_58 Trial04_KRLr4_59 Trial04_KRLr4_62
## [53] Trial04_KRLr4_65 Trial04_KRLr4_67 Trial04_KRLr4_68 Trial04_KRLr4_69
## [57] Trial04_KRLr4_70 Trial04_KRLr4_71 Trial04_KRLr4_75 Trial04_KRLr4_76
## 60 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
krillslopes70.filtered$SensoredSlope <- ""
krillslopes70.filtered$delta_t <- as.numeric(krillslopes70.filtered$delta_t)

krillslopes1hr.filtered
krillslopes1hr.filtered 
levels(krillslopes1hr.filtered$Treatment)
## [1] "CHG" "CUR" "n/a" "TMP"
unique(krillslopes1hr.filtered$KrillID)
##  [1] Trial01_KrilLR11 Trial01_KrilLR12 Trial01_KrilLR13 Trial01_KrilLR14
##  [5] Trial01_KrilLR15 Trial01_KrilLR16 Trial01_KrilLR17 Trial01_KrilLR18
##  [9] Trial01_KrilLR19 Trial01_KrILR110 Trial01_KriLR111 Trial01_KriLR112
## [13] Trial01_KriLR113 Trial01_KriLR114 Trial01_KriLR115 Trial01_KriLR116
## [17] Trial01_KriLR117 Trial01_KriLR118 Trial01_KriLR119 Trial02_KriLR220
## [21] Trial02_KriLR223 Trial02_KriLR224 Trial02_KriLR226 Trial02_KriLR227
## [25] Trial02_KriLR229 Trial02_KriLR230 Trial02_KriLR232 Trial02_KriLR233
## [29] Trial02_KriLR234 Trial02_KriLR235 Trial03_KRLr3_39 Trial03_KRLr3_40
## [33] Trial03_KRLr3_41 Trial03_KRLr3_42 Trial03_KRLr3_43 Trial03_KRLr3_44
## [37] Trial03_KRLr3_45 Trial03_KRLr3_46 Trial03_KRLr3_47 Trial03_KRLr3_48
## [41] Trial03_KRLr3_49 Trial03_KRLr3_50 Trial03_KRLr3_51 Trial03_KRLr3_52
## [45] Trial03_KRLr3_53 Trial03_KRLr3_54 Trial03_KRLr3_55 Trial03_KRLr3_56
## [49] Trial03_KRLr3_57 Trial04_KRLr4_58 Trial04_KRLr4_59 Trial04_KRLr4_62
## [53] Trial04_KRLr4_65 Trial04_KRLr4_67 Trial04_KRLr4_68 Trial04_KRLr4_69
## [57] Trial04_KRLr4_70 Trial04_KRLr4_71 Trial04_KRLr4_75 Trial04_KRLr4_76
## 60 Levels: Trial01_KrilLR11 Trial01_KrilLR12 ... Trial04_KRLr4_76
krillslopes1hr.filtered$SensoredSlope <- ""
krillslopes1hr.filtered$delta_t <- as.numeric(krillslopes1hr.filtered$delta_t)   

#nmol/vial; conversion for L to ml and umol to nmol cancels
#slope funcion of 2 vectors


slope <- function(y,x){
  return(lm(y~x, na.action = na.omit)$coefficients[2])
}
  
#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |




# For whole df without outliers
#T1to4krillslopes.filtered
cSlopesT1to4 <- by(T1to4krillslopes.filtered, T1to4krillslopes.filtered$KrillID, function(x){ slope(x$oxygen, x$delta_t)})


# for filtered dataframe with the 80% DO line, outliers excluded
# krillslopes80.filtered
cSlopes80 <- by(krillslopes80.filtered, krillslopes80.filtered$KrillID, function(x){ slope(x$oxygen, x$delta_t)})


# for filtered dataframe with the 70% DO line, outliers excluded
# krillslopes70.filtered
cSlopes70 <- by(krillslopes70.filtered, krillslopes70.filtered$KrillID, function(x){ slope(x$oxygen, x$delta_t)})


# for filtered dataframe with the 1hr line, outliers excluded
# krillslopes1hr.filtered
cSlopes1hr <- by(krillslopes1hr.filtered, krillslopes1hr.filtered$KrillID, function(x){ slope(x$oxygen, x$delta_t)})


#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

#creating a data frame instead of a list 
ksT1to4 <- as.data.frame(sapply(cSlopesT1to4, I))
ks80 <- as.data.frame(sapply(cSlopes80, I))
ks70 <- as.data.frame(sapply(cSlopes70, I))
ks1hr <- as.data.frame(sapply(cSlopes1hr, I))


# checking for unique observations


#having row names be a variable in a column to be able to pull it out for later merging 
ksT1to4$KrillID<- row.names(ksT1to4)
ks80$KrillID<- row.names(ks80)
ks70$KrillID<- row.names(ks70)
ks1hr$KrillID<- row.names(ks1hr)

18.) Merging ks… and krillslopes…

#add column to dslopes thats KrillID
#View(dref)



ksT1to4total <- merge(T1to4krillslopes.filtered, ksT1to4, by = "KrillID")
ks80total <- merge(krillslopes80.filtered, ks80, by = "KrillID")
ks70total <- merge(krillslopes70.filtered, ks70, by = "KrillID")
ks1hrtotal <- merge(krillslopes1hr.filtered, ks1hr, by = "KrillID")


#View(dtotal)

19.) Krill ID as a factor & Grouping by Krill ID - filtered DFs

# dtotal$KrillID <- factor(dtotal$KrillID)
# nlevels(dtotal$KrillID)

60 is the number of vials when Ambient Treatment is excluded

20.) Analysis, Respirometry - Creating Slope Functions & Linear Models

#*********************************
## 11.1) Creating the ds dataframe
#*********************************
# #get slopes and r^2 values 
#dtotal
#ksT1to4
#ks80
#ks70
#ks1hr


# ksT1to4total 
# ks80total 
# ks70total 
# ks1hrtotal 

###  ! ! ! Change all dSlopes to Krill Slopes etc...

dSlopes <- data.frame(KrillID = levels(dtotal$KrillID))
# dSlopes$slope <- NA
# dSlopes$rsq <- NA

for(i in 1:length(dSlopes$KrillID)){
   m <- lm(oxygen ~ delta_t,
                         dtotal[dtotal$KrillID == dSlopes$KrillID[i],],
                         na.action=na.omit)
  dSlopes$slope[i] <- m$coefficients[2]
  dSlopes$rsq[i] <- summary(m)$r.squared
}

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

krillslopes <- merge(dtotal, dSlopes, by="KrillID")

dSlopes$SensorName <- ""

dSlopes <- dSlopes %>% group_by(KrillID)
dRESPanimal <- dRESPanimal %>% group_by(SensorName)

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

dSlopes$KrillID <- as.character(dSlopes$KrillID)
dSlopes$SensorName <- dRESPanimal$SensorName
dSlopes$TrialID <- dRESPanimal$TrialID
dSlopes$MOATS <- dRESPanimal$MOATS
dSlopes$Treatment<- dRESPanimal$Treatment
dSlopes$LoadingLocation<- dRESPanimal$LoadingLocation
dSlopes$VialNum<- dRESPanimal$GlassVialNumber
dSlopes$TelsonLength<- dRESPanimal$TelsonLength..mm.
dSlopes$WetWeight<- dRESPanimal$Size

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

20.1a) Analysis, Respirometry - Creating Slope Functions & Linear Models 80% cutoff

#*********************************
## 20.1a) Using the 80% dataframe
#*********************************
# #get slopes and r^2 values from dtotal 

#dtotal

# ksT1to4total 
# ks80total 
# ks70total 
# ks1hrtotal 



###  ! ! ! Change all dSlopes to Krill Slopes etc...
# ks80total 
ksSlopes80 <- data.frame(KrillID = levels(ks80total$KrillID))

for(i in 1:length(ksSlopes80$KrillID)){
   m <- lm(oxygen ~ delta_t,
                         ks80total[ks80$KrillID == ksSlopes80$KrillID[i],],
                         na.action=na.omit)
  ksSlopes80$slope[i] <- m$coefficients[2]
  ksSlopes80$rsq[i] <- summary(m)$r.squared
}

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# krillSlopes80 <- merge(ksSlopes80, ks80total, by="KrillID")

# krillslopes80$SensorName <- ""

ksSlopes80 <- ksSlopes80 %>% group_by(KrillID)
dRESPanimal80 <- dRESPanimal
dRESPanimal80 <- filter(dRESPanimal, Treatment != "AMB")
dRESPanimal80 <- dRESPanimal80 %>% group_by(SensorName)

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

ksSlopes80$KrillID <- as.character(ksSlopes80$KrillID)
ksSlopes80$SensorName <- dRESPanimal80$SensorName
ksSlopes80$TrialID <- dRESPanimal80$TrialID
ksSlopes80$MOATS <- dRESPanimal80$MOATS
ksSlopes80$Treatment<- dRESPanimal80$Treatment
ksSlopes80$LoadingLocation<- dRESPanimal80$LoadingLocation
ksSlopes80$VialNum<- dRESPanimal80$GlassVialNumber
ksSlopes80$TelsonLength<- dRESPanimal80$TelsonLength..mm.
ksSlopes80$WetWeight<- dRESPanimal80$Size

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

20.1b) Analysis, Respirometry - Creating Slope Functions & Linear Models 70% cutoff

#*********************************
## 20.1b) Using the 70% dataframe
#*********************************
# #get slopes and r^2 values from dtotal 

#dtotal

# ksT1to4total 
# ks80total 
# ks70total 
# ks1hrtotal 



###  ! ! ! Change all dSlopes to Krill Slopes etc...
# ks80total 
ksSlopes70 <- data.frame(KrillID = levels(ks70total$KrillID))

for(i in 1:length(ksSlopes70$KrillID)){
   m <- lm(oxygen ~ delta_t,
                         ks70total[ks70$KrillID == ksSlopes70$KrillID[i],],
                         na.action=na.omit)
  ksSlopes70$slope[i] <- m$coefficients[2]
  ksSlopes70$rsq[i] <- summary(m)$r.squared
}

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |


ksSlopes70 <- ksSlopes70 %>% group_by(KrillID)
dRESPanimal70 <- dRESPanimal
dRESPanimal70 <- filter(dRESPanimal, Treatment != "AMB")
dRESPanimal70 <- dRESPanimal70 %>% group_by(SensorName)

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

ksSlopes70$KrillID <- as.character(ksSlopes70$KrillID)

ksSlopes70$SensorName <- dRESPanimal70$SensorName

ksSlopes70$TrialID <- dRESPanimal70$TrialID
ksSlopes70$MOATS <- dRESPanimal70$MOATS
ksSlopes70$Treatment<- dRESPanimal70$Treatment
ksSlopes70$LoadingLocation<- dRESPanimal70$LoadingLocation
ksSlopes70$VialNum<- dRESPanimal70$GlassVialNumber
ksSlopes70$TelsonLength<- dRESPanimal70$TelsonLength..mm.
ksSlopes70$WetWeight<- dRESPanimal70$Size

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

20.1c) Analysis, Respirometry - Creating Slope Functions & Linear Models 1hr cutoff

#*********************************
## 20.1c) Using the 1hr cuttoff dataframe
#*********************************
# #get slopes and r^2 values from dtotal 

#dtotal

# ksT1to4total 
# ks80total 
# ks70total 
# ks1hrtotal 



###  ! ! ! Change all dSlopes to Krill Slopes etc...
# ks80total 
ksSlopes1hr <- data.frame(KrillID = levels(ks1hrtotal$KrillID))

for(i in 1:length(ksSlopes1hr$KrillID)){
   m <- lm(oxygen ~ delta_t,
                         ks1hrtotal[ks1hr$KrillID == ksSlopes1hr$KrillID[i],],
                         na.action=na.omit)
  ksSlopes1hr$slope[i] <- m$coefficients[2]
  ksSlopes1hr$rsq[i] <- summary(m)$r.squared
}

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |


ksSlopes1hr <- ksSlopes1hr %>% group_by(KrillID)
dRESPanimal1hr <- dRESPanimal
dRESPanimal1hr <- filter(dRESPanimal, Treatment != "AMB")
dRESPanimal1hr <- dRESPanimal1hr %>% group_by(SensorName)

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

ksSlopes1hr$KrillID <- as.character(ksSlopes70$KrillID)

ksSlopes1hr$SensorName <- dRESPanimal70$SensorName

ksSlopes1hr$TrialID <- dRESPanimal1hr$TrialID
ksSlopes1hr$MOATS <- dRESPanimal1hr$MOATS
ksSlopes1hr$Treatment<- dRESPanimal1hr$Treatment
ksSlopes1hr$LoadingLocation<- dRESPanimal1hr$LoadingLocation
ksSlopes1hr$VialNum<- dRESPanimal1hr$GlassVialNumber
ksSlopes1hr$TelsonLength<- dRESPanimal1hr$TelsonLength..mm.
ksSlopes1hr$WetWeight<- dRESPanimal1hr$Size

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

21.) Analysis, Respirometry - Correcting the Slope for Blanks

#*********************************
## 21.) Analysis, Respirometry - Correcting the Slope for Blanks 
#*********************************

#blank corrected slope and blank-size corrected slope
## need to correct all slopes with the blanks' slope
## this is the background respiration of whatever phtyos and instrument drift
## create a mean blank slope per trial
## merge with the master(krill slopes) and "correct" all slopes against mean value (per trial)
# x is equal to the blank vials  

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# Creating four separate means from the blank vials per trial
x <- subset(dSlopes, dSlopes$MOATS == "blank")

xtrial1 <- subset(x, x$TrialID == "Trial01")
xtrial2 <- subset(x, x$TrialID == "Trial02")
xtrial3 <- subset(x, x$TrialID == "Trial03")
xtrial4 <- subset(x, x$TrialID == "Trial04")

blankmeanslope1 <- mean(xtrial1$slope)
blankmeanslope2 <- mean(xtrial2$slope)
blankmeanslope3 <- mean(xtrial3$slope)
blankmeanslope4 <- mean(xtrial4$slope)

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

#Creating new corrected variables for slopes adjusted for blank vials and size of animal
dSlopes$CorrSlope <- ""
dSlopes$CorrSlope <- as.numeric(dSlopes$CorrSlope)
dSlopes$slope <- as.numeric(dSlopes$slope)

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# Conditional Statement directing certain means to their respective trials
# take absolute values not to add a negative nubmer

dSlopes <- dSlopes %>% mutate(CorrSlope=case_when(
    (dSlopes$MOATS == "blank" ~ dSlopes$slope),
    (dSlopes$TrialID == "Trial01" ~ dSlopes$slope-((blankmeanslope1))),
    (dSlopes$TrialID == "Trial02" ~ dSlopes$slope-((blankmeanslope2))),
    (dSlopes$TrialID == "Trial03" ~ dSlopes$slope-((blankmeanslope3))),
    (dSlopes$TrialID == "Trial04" ~ dSlopes$slope-((blankmeanslope4))),
    TRUE ~ as.numeric(0)
))


# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# Correcting for the size of the animal 
dSlopes$WetWeight <- as.numeric(dSlopes$WetWeight)
dSlopes$WetWeightSlope <- dSlopes$CorrSlope/dSlopes$WetWeight

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |


#create plots and perhaps convert to larger units

21. Summary Statisitics on the Unfiltered Dataframe dSlopes

factor(dSlopes$TrialID)
##  [1] Trial01 Trial01 Trial01 Trial01 Trial01 Trial01 Trial01 Trial01 Trial01
## [10] Trial01 Trial01 Trial01 Trial01 Trial01 Trial01 Trial01 Trial01 Trial01
## [19] Trial01 Trial02 Trial02 Trial02 Trial02 Trial02 Trial02 Trial02 Trial02
## [28] Trial02 Trial02 Trial02 Trial02 Trial02 Trial02 Trial02 Trial02 Trial02
## [37] Trial02 Trial02 Trial03 Trial03 Trial03 Trial03 Trial03 Trial03 Trial03
## [46] Trial03 Trial03 Trial03 Trial03 Trial03 Trial03 Trial03 Trial03 Trial03
## [55] Trial03 Trial03 Trial03 Trial04 Trial04 Trial04 Trial04 Trial04 Trial04
## [64] Trial04 Trial04 Trial04 Trial04 Trial04 Trial04 Trial04 Trial04 Trial04
## [73] Trial04 Trial04 Trial04 Trial04
## Levels: Trial01 Trial02 Trial03 Trial04
dSlopes <- filter(dSlopes, Treatment != "AMB")  
dSlopes<- droplevels(filter(dSlopes, Treatment != "AMB"))
dSlopes<- droplevels(filter(dSlopes, Treatment != "n/a"))

dSlopes.summary <- dSlopes %>% group_by(Treatment) %>%
  dplyr::summarize(sd = sd(CorrSlope, na.rm = TRUE), 
            mean = mean(CorrSlope, na.rm = TRUE), 
            median = median(CorrSlope, na.rm = TRUE),
            IQR = IQR(CorrSlope, na.rm = TRUE),
            n = n()) %>%
  mutate(se = sd/sqrt(n)) %>%
  mutate(ci = se*1.96)
## `summarise()` ungrouping output (override with `.groups` argument)
dSlopes.summary
kable(dSlopes.summary, digits = 4)
Treatment sd mean median IQR n se ci
CHG 0.0043 -0.0081 -0.0078 0.0072 16 0.0011 0.0021
CUR 0.0067 -0.0103 -0.0099 0.0092 19 0.0015 0.0030
TMP 0.0068 -0.0098 -0.0086 0.0095 16 0.0017 0.0033
write.csv(dSlopes.summary, "2021.01.26_dSlopes_summary.csv")

21.a) Summary Statistics Graphed with Standard dSlope Values

dSlopesplot <- ggplot(dSlopes, aes(Treatment, CorrSlope)) +
            geom_jitter(color = "grey") +
            geom_jitter(data = dSlopes, aes(Treatment, CorrSlope)) +
            # geom_jitter(data = krillslopes80.filtered, aes(Treatment, slope)) +
            # geom_jitter(data = krillslopes70.filtered, aes(Treatment, slope)) +
            # geom_jitter(data = T1to4krillslopes.filtered, aes(Treatment, slope)) +
            # geom_jitter(aes(colour = Treatment)) +
            geom_boxplot(notch = TRUE, outlier.shape = NA, colour = "green") +
            geom_point(data = dSlopes.summary, aes(x=Treatment, y=mean), size=5, color = "purple") + 
            geom_errorbar(data = dSlopes.summary, 
                          aes(x=Treatment, y=mean, ymin = mean-sd, ymax = mean+sd), 
                          color = "blue") +
            geom_errorbar(data = dSlopes.summary,
                          aes(x=Treatment, y=mean, ymin = mean-ci, ymax = mean+ci),
                          colour = "red") +
            # facet_wrap(~TrialID) +
            ggtitle("Standard dSlopes Values grouped by Treatment and Corrected Slope") +
            theme_bw() 

dSlopesplot

kable(dSlopes.summary, digits = 4)
Treatment sd mean median IQR n se ci
CHG 0.0043 -0.0081 -0.0078 0.0072 16 0.0011 0.0021
CUR 0.0067 -0.0103 -0.0099 0.0092 19 0.0015 0.0030
TMP 0.0068 -0.0098 -0.0086 0.0095 16 0.0017 0.0033

21.b) Analysis, Respirometry - Correcting the Slope for Blanks - 80% cutoff

#*********************************
## 21.b) Analysis, Respirometry - Correcting the Slope for Blanks  - 80% cutoff
#*********************************

#blank corrected slope and blank-size corrected slope
## need to correct all slopes with the blanks' slope
## this is the background respiration of whatever phtyos and instrument drift
## create a mean blank slope per trial
## merge with the master(krill slopes) and "correct" all slopes against mean value (per trial)
# x is equal to the blank vials  

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# Creating four separate means from the blank vials per trial
x80 <- subset(ksSlopes80, ksSlopes80$MOATS == "blank")

x80trial1 <- subset(x80, x80$TrialID == "Trial01")
x80trial2 <- subset(x80, x80$TrialID == "Trial02")
x80trial3 <- subset(x80, x80$TrialID == "Trial03")
x80trial4 <- subset(x80, x80$TrialID == "Trial04")

blank80meanslope1 <- mean(x80trial1$slope)
blank80meanslope2 <- mean(x80trial2$slope)
blank80meanslope3 <- mean(x80trial3$slope)
blank80meanslope4 <- mean(x80trial4$slope)

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

#Creating new corrected variables for slopes adjusted for blank vials and size of animal
ksSlopes80$CorrSlope <- ""
ksSlopes80$CorrSlope <- as.numeric(ksSlopes80$CorrSlope)
ksSlopes80$slope <- as.numeric(ksSlopes80$slope)

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# Conditional Statement directing certain means to their respective trials
# take absolute values not to add a negative nubmer

ksSlopes.80 <- ksSlopes80 %>% mutate(CorrSlope=case_when(
    (ksSlopes80$MOATS == "blank" ~ ksSlopes80$slope),
    (ksSlopes80$TrialID == "Trial01" ~ ksSlopes80$slope-((blank80meanslope1))),
    (ksSlopes80$TrialID == "Trial02" ~ ksSlopes80$slope-((blank80meanslope2))),
    (ksSlopes80$TrialID == "Trial03" ~ ksSlopes80$slope-((blank80meanslope3))),
    (ksSlopes80$TrialID == "Trial04" ~ ksSlopes80$slope-((blank80meanslope4))),
    TRUE ~ as.numeric(0)
))

ksSlopes80 <- ksSlopes.80


# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# Correcting for the size of the animal 
ksSlopes80$WetWeight <- as.numeric(ksSlopes80$WetWeight)
ksSlopes80$WetWeightSlope <- ksSlopes80$CorrSlope/ksSlopes80$WetWeight

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |


#create plots and perhaps convert to larger units

21.c) Summary Statisitics on the Unfiltered Dataframe dSlopes

# factor(dSlopes$TrialID)
# 
# dSlopes <- filter(dSlopes, Treatment != "AMB")  
ksSlopes80<- droplevels(filter(ksSlopes80, Treatment != "n/a"))

ksSlopes80.summary <- ksSlopes80 %>% group_by(Treatment) %>%
  dplyr::summarize(sd = sd(CorrSlope, na.rm = TRUE), 
            mean = mean(CorrSlope, na.rm = TRUE), 
            median = median(CorrSlope, na.rm = TRUE),
            IQR = IQR(CorrSlope, na.rm = TRUE),
            n = n()) %>%
  mutate(se = sd/sqrt(n)) %>%
  mutate(ci = se*1.96)
## `summarise()` ungrouping output (override with `.groups` argument)
ksSlopes80.summary
kable(ksSlopes80.summary, digits = 4)
Treatment sd mean median IQR n se ci
CHG 0.0041 0.0006 0.0014 0.0021 16 1e-03 0.0020
CUR 0.0033 -0.0010 -0.0007 0.0037 19 8e-04 0.0015
TMP 0.0035 0.0011 0.0006 0.0052 16 9e-04 0.0017
write.csv(ksSlopes80.summary, "2021.01.26_ksSlopes80_summary.csv")

21.d) Analysis, Respirometry - Correcting the Slope for Blanks - 70% cutoff

#*********************************
## 21.d) Analysis, Respirometry - Correcting the Slope for Blanks  - 80% cutoff
#*********************************

#blank corrected slope and blank-size corrected slope
## need to correct all slopes with the blanks' slope
## this is the background respiration of whatever phtyos and instrument drift
## create a mean blank slope per trial
## merge with the master(krill slopes) and "correct" all slopes against mean value (per trial)
# x is equal to the blank vials  

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# Creating four separate means from the blank vials per trial
x70 <- subset(ksSlopes70, ksSlopes70$MOATS == "blank")

x70trial1 <- subset(x70, x70$TrialID == "Trial01")
x70trial2 <- subset(x70, x70$TrialID == "Trial02")
x70trial3 <- subset(x70, x70$TrialID == "Trial03")
x70trial4 <- subset(x70, x70$TrialID == "Trial04")

blank70meanslope1 <- mean(x70trial1$slope)
blank70meanslope2 <- mean(x70trial2$slope)
blank70meanslope3 <- mean(x70trial3$slope)
blank70meanslope4 <- mean(x70trial4$slope)

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

#Creating new corrected variables for slopes adjusted for blank vials and size of animal
ksSlopes70$CorrSlope <- ""
ksSlopes70$CorrSlope <- as.numeric(ksSlopes70$CorrSlope)
ksSlopes70$slope <- as.numeric(ksSlopes70$slope)

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# Conditional Statement directing certain means to their respective trials
# take absolute values not to add a negative nubmer

ksSlopes.70 <- ksSlopes70 %>% mutate(CorrSlope=case_when(
    (ksSlopes70$MOATS == "blank" ~ ksSlopes70$slope),
    (ksSlopes70$TrialID == "Trial01" ~ ksSlopes70$slope-((blank70meanslope1))),
    (ksSlopes70$TrialID == "Trial02" ~ ksSlopes70$slope-((blank70meanslope2))),
    (ksSlopes70$TrialID == "Trial03" ~ ksSlopes70$slope-((blank70meanslope3))),
    (ksSlopes70$TrialID == "Trial04" ~ ksSlopes70$slope-((blank70meanslope4))),
    TRUE ~ as.numeric(0)
))


ksSlopes70 <- ksSlopes.70

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# Correcting for the size of the animal 
ksSlopes70$WetWeight <- as.numeric(ksSlopes70$WetWeight)
ksSlopes70$WetWeightSlope <- ksSlopes70$CorrSlope/ksSlopes70$WetWeight

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |


#create plots and perhaps convert to larger units

21.e Summary Statisitics on the Unfiltered Dataframe dSlopes

# factor(dSlopes$TrialID)
# 
# dSlopes <- filter(dSlopes, Treatment != "AMB")  
# dSlopes<- droplevels(filter(dSlopes, Treatment != "AMB"))

ksSlopes70<- droplevels(filter(ksSlopes70, Treatment != "n/a"))

ksSlopes70.summary <- ksSlopes70 %>% group_by(Treatment) %>%
  dplyr::summarize(sd = sd(CorrSlope, na.rm = TRUE), 
            mean = mean(CorrSlope, na.rm = TRUE), 
            median = median(CorrSlope, na.rm = TRUE),
            IQR = IQR(CorrSlope, na.rm = TRUE),
            n = n()) %>%
  mutate(se = sd/sqrt(n)) %>%
  mutate(ci = se*1.96)
## `summarise()` ungrouping output (override with `.groups` argument)
ksSlopes70.summary
kable(ksSlopes70.summary, digits = 4)
Treatment sd mean median IQR n se ci
CHG 0.0032 -5e-04 0e+00 0.0029 16 8e-04 0.0016
CUR 0.0023 -3e-04 0e+00 0.0024 19 5e-04 0.0010
TMP 0.0028 2e-04 4e-04 0.0038 16 7e-04 0.0014
write.csv(ksSlopes70.summary, "2021.01.26_ksSlopes70_summary.csv")

21.f) Analysis, Respirometry - Correcting the Slope for Blanks - 1hr cutoff

#*********************************
## 21.f) Analysis, Respirometry - Correcting the Slope for Blanks  - 1hr cutoff
#*********************************

#blank corrected slope and blank-size corrected slope
## need to correct all slopes with the blanks' slope
## this is the background respiration of whatever phtyos and instrument drift
## create a mean blank slope per trial
## merge with the master(krill slopes) and "correct" all slopes against mean value (per trial)
# x is equal to the blank vials  

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

# Creating four separate means from the blank vials per trial
x1hr <- subset(ksSlopes1hr, ksSlopes1hr$MOATS == "blank")

x1hrtrial1 <- subset(x1hr, x1hr$TrialID == "Trial01")
x1hrtrial2 <- subset(x1hr, x1hr$TrialID == "Trial02")
x1hrtrial3 <- subset(x1hr, x1hr$TrialID == "Trial03")
x1hrtrial4 <- subset(x1hr, x1hr$TrialID == "Trial04")

blank1hrmeanslope1 <- mean(x1hrtrial1$slope)
blank1hrmeanslope2 <- mean(x1hrtrial2$slope)
blank1hrmeanslope3 <- mean(x1hrtrial3$slope)
blank1hrmeanslope4 <- mean(x1hrtrial4$slope)

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |

#Creating new corrected variables for slopes adjusted for blank vials and size of animal
ksSlopes1hr$CorrSlope <- ""
ksSlopes1hr$CorrSlope <- as.numeric(ksSlopes1hr$CorrSlope)
ksSlopes1hr$slope <- as.numeric(ksSlopes1hr$slope)

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# Conditional Statement directing certain means to their respective trials
# take absolute values not to add a negative nubmer

ksSlopes.1hr <- ksSlopes1hr %>% mutate(CorrSlope=case_when(
    (ksSlopes1hr$MOATS == "blank" ~ ksSlopes1hr$slope),
    (ksSlopes1hr$TrialID == "Trial01" ~ ksSlopes1hr$slope-((blank1hrmeanslope1))),
    (ksSlopes1hr$TrialID == "Trial02" ~ ksSlopes1hr$slope-((blank1hrmeanslope2))),
    (ksSlopes1hr$TrialID == "Trial03" ~ ksSlopes1hr$slope-((blank1hrmeanslope3))),
    (ksSlopes1hr$TrialID == "Trial04" ~ ksSlopes1hr$slope-((blank1hrmeanslope4))),
    TRUE ~ as.numeric(0)
))


ksSlopes1hr <- ksSlopes.1hr

# #|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
# Correcting for the size of the animal 
ksSlopes1hr$WetWeight <- as.numeric(ksSlopes1hr$WetWeight)
ksSlopes1hr$WetWeightSlope <- ksSlopes1hr$CorrSlope/ksSlopes1hr$WetWeight

#|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |


#create plots and perhaps convert to larger units

Executive Summary

21.g Summary Statisitics on the Unfiltered Dataframe dSlopes

# factor(dSlopes$TrialID)
# 
# dSlopes <- filter(dSlopes, Treatment != "AMB")  
# dSlopes<- droplevels(filter(dSlopes, Treatment != "AMB"))
ksSlopes1hr<- droplevels(filter(ksSlopes1hr, Treatment != "n/a"))

ksSlopes1hr.summary <- ksSlopes1hr %>% group_by(Treatment) %>%
  dplyr::summarize(sd = sd(CorrSlope, na.rm = TRUE), 
            mean = mean(CorrSlope, na.rm = TRUE), 
            median = median(CorrSlope, na.rm = TRUE),
            IQR = IQR(CorrSlope, na.rm = TRUE),
            n = n()) %>%
  mutate(se = sd/sqrt(n)) %>%
  mutate(ci = se*1.96)
## `summarise()` ungrouping output (override with `.groups` argument)
ksSlopes1hr.summary
kable(ksSlopes1hr.summary, digits = 4)
Treatment sd mean median IQR n se ci
CHG 0.0056 -0.0018 -0.0020 0.0049 16 0.0014 0.0027
CUR 0.0113 0.0024 0.0010 0.0051 19 0.0026 0.0051
TMP 0.0048 -0.0025 -0.0037 0.0057 16 0.0012 0.0024
write.csv(ksSlopes1hr.summary, "2026.01.26_ksSlopes1hr_summary.csv")

22.) 80% Slope for Corrected Slopes

plot80 <- ggplot(ksSlopes80, aes(Treatment, CorrSlope)) +
            geom_jitter(color = "grey") +
            geom_jitter(data = ksSlopes80, aes(Treatment, CorrSlope)) +
            # geom_jitter(data = krillslopes80.filtered, aes(Treatment, slope)) +
            # geom_jitter(data = krillslopes70.filtered, aes(Treatment, slope)) +
            # geom_jitter(data = T1to4krillslopes.filtered, aes(Treatment, slope)) +
            # geom_jitter(aes(colour = Treatment)) +
            geom_boxplot(notch = TRUE, outlier.shape = NA, colour = "green") +
            geom_point(data = ksSlopes80.summary, aes(x=Treatment, y=mean), size=5, color = "purple") + 
            geom_errorbar(data = ksSlopes80.summary, 
                          aes(x=Treatment, y=mean, ymin = mean-sd, ymax = mean+sd), 
                          color = "blue") +
            geom_errorbar(data = ksSlopes80.summary,
                          aes(x=Treatment, y=mean, ymin = mean-ci, ymax = mean+ci),
                          colour = "red") +
            # facet_wrap(~TrialID) +
            ggtitle("ksSlopes80, (80% oxygen) Corrected Slope") +
            theme_bw() 


plot80

The purple dots represent the mean- all trials included Confidence Intervals set to 95 Green boxplots show from the 25th percentil to the 75th percentile error bars +/- SD shown in blue error bars(CI) +/- our confidence intervals- shown in red

23.) 70% Slope for Corrected Slopes

plot70 <- ggplot(ksSlopes70, aes(Treatment, CorrSlope)) +
            geom_jitter(color = "grey") +
            geom_jitter(data = ksSlopes70, aes(Treatment, CorrSlope)) +
            # geom_jitter(data = krillslopes80.filtered, aes(Treatment, slope)) +
            # geom_jitter(data = krillslopes70.filtered, aes(Treatment, slope)) +
            # geom_jitter(data = T1to4krillslopes.filtered, aes(Treatment, slope)) +
            # geom_jitter(aes(colour = Treatment)) +
            geom_boxplot(notch = TRUE, outlier.shape = NA, colour = "green") +
            geom_point(data = ksSlopes70.summary, aes(x=Treatment, y=mean), size=5, color = "purple") + 
            geom_errorbar(data = ksSlopes70.summary, 
                          aes(x=Treatment, y=mean, ymin = mean-sd, ymax = mean+sd), 
                          color = "blue") +
            geom_errorbar(data = ksSlopes70.summary,
                          aes(x=Treatment, y=mean, ymin = mean-ci, ymax = mean+ci),
                          colour = "red") +
            # facet_wrap(~TrialID) +
            ggtitle("ksSlopes70, (70% oxygen) Corrected Slope") +
            theme_bw() 

plot70
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

The purple dots represent the mean- all trials included Confidence Intervals set to 95 Green boxplots show from the 25th percentil to the 75th percentile error bars +/- SD shown in blue error bars(CI) +/- our confidence intervals- shown in red

24.) 1hr cutoff Slope for Corrected Slopes

Onehrplot <- ggplot(ksSlopes1hr, aes(Treatment, CorrSlope)) +
            geom_jitter(color = "grey") +
            geom_jitter(data = ksSlopes1hr, aes(Treatment, CorrSlope)) +
            # geom_jitter(data = krillslopes80.filtered, aes(Treatment, slope)) +
            # geom_jitter(data = krillslopes70.filtered, aes(Treatment, slope)) +
            # geom_jitter(data = T1to4krillslopes.filtered, aes(Treatment, slope)) +
            # geom_jitter(aes(colour = Treatment)) +
            geom_boxplot(notch = TRUE, outlier.shape = NA, colour = "green") +
            geom_point(data = ksSlopes1hr.summary, aes(x=Treatment, y=mean), size=5, color = "purple") + 
            geom_errorbar(data = ksSlopes1hr.summary, 
                          aes(x=Treatment, y=mean, ymin = mean-sd, ymax = mean+sd), 
                          color = "blue") +
            geom_errorbar(data = ksSlopes1hr.summary,
                          aes(x=Treatment, y=mean, ymin = mean-ci, ymax = mean+ci),
                          colour = "red") +
            # facet_wrap(~TrialID) +
            ggtitle("ksSlopes1hr, (1hr cutoff) Corrected Slope") +
            theme_bw() 

Onehrplot 
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

The purple dots represent the mean- all trials included Confidence Intervals set to 95 Green boxplots show from the 25th percentil to the 75th percentile error bars +/- SD shown in blue error bars(CI) +/- our confidence intervals- shown in red

25.) Descriptive Statisitics

library(tidyr)
#Remove NAs
#krill <- na.omit(krill)
#Calculate mean and standard deviation for each treatment per each dataset
# blanks are to be removed from treatments

dSlopes<- droplevels(filter(dSlopes, Treatment != "n/a"))
ksSlopes80<- droplevels(filter(ksSlopes80, Treatment != "n/a"))
ksSlopes70<- droplevels(filter(ksSlopes70, Treatment != "n/a"))
ksSlopes1hr<- droplevels(filter(ksSlopes1hr, Treatment != "n/a"))


dSlopes_Avg <- tapply(dSlopes$CorrSlope, (dSlopes$Treatment), mean)
dSlopes_Med <- tapply(dSlopes$CorrSlope, (dSlopes$Treatment), median)
dSlopes_Std <- tapply(dSlopes$CorrSlope, (dSlopes$Treatment), sd)

ksSlopes80_Avg <- tapply(ksSlopes80$CorrSlope, (ksSlopes80$Treatment), mean)
ksSlopes80_Med <- tapply(ksSlopes80$CorrSlope, (ksSlopes80$Treatment), median)
ksSlopes80_Std <- tapply(ksSlopes80$CorrSlope, (ksSlopes80$Treatment), sd)

ksSlopes70_Avg <- tapply(ksSlopes70$CorrSlope, (ksSlopes70$Treatment), mean)
ksSlopes70_Med <- tapply(ksSlopes70$CorrSlope, (ksSlopes70$Treatment), median)
ksSlopes70_Std <- tapply(ksSlopes70$CorrSlope, (ksSlopes70$Treatment), sd)

ksSlopes1hr_Avg <- tapply(ksSlopes1hr$CorrSlope, (ksSlopes1hr$Treatment), mean)
ksSlopes1hr_Med <- tapply(ksSlopes1hr$CorrSlope, (ksSlopes1hr$Treatment), median)
ksSlopes1hr_Std <- tapply(ksSlopes1hr$CorrSlope, (ksSlopes1hr$Treatment), sd)


#Put it all together
Slope_Stats <- cbind(dSlopes_Avg, dSlopes_Med, dSlopes_Std,
                     ksSlopes80_Avg, ksSlopes80_Med, ksSlopes80_Std,
                     ksSlopes70_Avg, ksSlopes70_Med, ksSlopes70_Std,
                     ksSlopes1hr_Avg, ksSlopes1hr_Med, ksSlopes1hr_Std)

colnames(Slope_Stats) [1:12] <-c("Avg All Points Corrected Slopes", "Med All Points Corrected Slopes", "All Points Corrected Slopes SD", "Avg 80% DO Corrected Slopes", "Med 80% DO Corrected Slopes", "80% DO Corrected Slopes SD", "Avg 70% DO Corrected Slopes", "Med 70% DO Corrected Slopes", "70% DO Corrected Slopes SD", "Avg 1hr Corrected Slopes", "Med 1hr Corrected Slopes", "1hr Corrected Slopes SD")


write.csv(Slope_Stats, "2020.01.26_Slope_Stats.csv")

kable(Slope_Stats)
Avg All Points Corrected Slopes Med All Points Corrected Slopes All Points Corrected Slopes SD Avg 80% DO Corrected Slopes Med 80% DO Corrected Slopes 80% DO Corrected Slopes SD Avg 70% DO Corrected Slopes Med 70% DO Corrected Slopes 70% DO Corrected Slopes SD Avg 1hr Corrected Slopes Med 1hr Corrected Slopes 1hr Corrected Slopes SD
CHG -0.0081069 -0.0077957 0.0042656 0.0005786 0.0014299 0.0040655 -0.0004976 -0.0000416 0.0031732 -0.0017762 -0.0020364 0.0055834
CUR -0.0103312 -0.0098989 0.0066749 -0.0010072 -0.0006883 0.0032839 -0.0003071 -0.0000257 0.0022988 0.0023796 0.0010210 0.0112983
TMP -0.0097526 -0.0086015 0.0067831 0.0010753 0.0006013 0.0034942 0.0002339 0.0004077 0.0028139 -0.0025005 -0.0036506 0.0048384

26.) Fitting my Linear Mixed-Effects Models to my Dataframes

#Using a mixed model to find significant differences bertween MOATs
#library(nlme)
library(lme4)
library(lmerTest)

# Corrected Slopes , Treatment taking into account MOATS


ksSlopes.80<- droplevels(filter(ksSlopes.80, Treatment != "n/a"))
ksSlopes.70<- droplevels(filter(ksSlopes.70, Treatment != "n/a"))
ksSlopes.1hr<- droplevels(filter(ksSlopes.1hr, Treatment != "n/a"))
dSlopes<- droplevels(filter(dSlopes, Treatment != "n/a"))


ksSlopes.1hr_howmanyanimalsin_CHG <- subset(ksSlopes.1hr, Treatment == "CHG")
ks1hrCHGno <- unique(ksSlopes.1hr_howmanyanimalsin_CHG$KrillID)
# 16 animals in All Change across 4 trials

ksSlopes.1hr_howmanyanimalsin_CUR <- subset(ksSlopes.1hr, Treatment == "CUR")
ks1hrCURno <- unique(ksSlopes.1hr_howmanyanimalsin_CUR$KrillID)
# 19 animals from Current Treatment across 4 trials

ksSlopes.1hr_howmanyanimalsin_TMP <- subset(ksSlopes.1hr, Treatment == "TMP")
ks1hrTMPno <- unique(ksSlopes.1hr_howmanyanimalsin_TMP$KrillID)
# 16 animals in high Temperature Treatment across 4 trials


16+19+16
## [1] 51
# [1] 51

26.a) 1hr Dataframe - LMER

lmer.ksSlopes.1hr <- lmer(CorrSlope ~ Treatment + (1|MOATS), data = ksSlopes.1hr)
summary(lmer.ksSlopes.1hr)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CorrSlope ~ Treatment + (1 | MOATS)
##    Data: ksSlopes.1hr
## 
## REML criterion at convergence: -329.1
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.68638 -0.47569  0.00437  0.51632  2.75955 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  MOATS    (Intercept) 3.441e-05 0.005866
##  Residual             4.178e-05 0.006464
## Number of obs: 51, groups:  MOATS, 9
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)
## (Intercept)  -0.001302   0.003369  8.777260  -0.386    0.708
## TreatmentCUR  0.004016   0.004212 14.743842   0.953    0.356
## TreatmentTMP -0.001199   0.005583  6.333602  -0.215    0.837
## 
## Correlation of Fixed Effects:
##             (Intr) TrtCUR
## TreatmntCUR -0.670       
## TreatmntTMP -0.604  0.405
# All Change Against Current 
# All Change Against High Temperature

“1hr Dataset” - No Treatment Effect Found

Random Effects Model variance accounting for a possible MOATs effect remains significantly small. No treatment effect observed. Neither correlation or T values between “All Change(CHG)” to “Current(CUR)” and “High Temperature(TMP)” This model doesn’t consider High Temperature directly against Current Model re-ogranized/re-leveled below

26.b) 1hr Dataframe - LMER releved Current 1st

levels(ksSlopes.1hr$Treatment)
## [1] "CHG" "CUR" "TMP"
# lmer.ksSlopes.1hr 
ksSlopes.1hr$Treatment <- fct_relevel(ksSlopes.1hr$Treatment, "CUR")
lmer.ksSlopes.1hr <- lmer(CorrSlope ~ Treatment + (1|MOATS), data = ksSlopes.1hr)
summary(lmer.ksSlopes.1hr)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CorrSlope ~ Treatment + (1 | MOATS)
##    Data: ksSlopes.1hr
## 
## REML criterion at convergence: -329.1
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.68638 -0.47569  0.00437  0.51632  2.75955 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  MOATS    (Intercept) 3.441e-05 0.005866
##  Residual             4.178e-05 0.006464
## Number of obs: 51, groups:  MOATS, 9
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)
## (Intercept)   0.002713   0.003173  8.789085   0.855    0.415
## TreatmentCHG -0.004016   0.004212 14.743842  -0.953    0.356
## TreatmentTMP -0.005214   0.005467  6.253781  -0.954    0.376
## 
## Correlation of Fixed Effects:
##             (Intr) TrtCHG
## TreatmntCHG -0.616       
## TreatmntTMP -0.580  0.357

The Current Conditions to Hight Temperature comparison did not display a treatment effect.

Possible reasons for such small amount of variance include only 51 animals in trial. 16 animals from the “All Change” treatment were in included across four trials. 19 animals from the “Current” treatment were in included across four trials. 16 animals from the “High Temperarure” treatment were in included across four trials. (totals 51 animals)

so signal over the noise- why?

1hr may not have allowed enough observations to show a disernable difference across treatments. However, Krill could just be proving to be a robust organism, able to withstand a cross stress environment. It’s more likely that sample size was small.

26.c) 80% Threshold Dataframe - LMER

lmer.ksSlopes.80 <- lmer(CorrSlope ~ Treatment + (1|MOATS), data = ksSlopes.80)
summary(lmer.ksSlopes.80)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CorrSlope ~ Treatment + (1 | MOATS)
##    Data: ksSlopes.80
## 
## REML criterion at convergence: -395.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4943 -0.5586  0.1519  0.5739  1.4604 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. 
##  MOATS    (Intercept) 2.347e-07 0.0004845
##  Residual             1.287e-05 0.0035869
## Number of obs: 51, groups:  MOATS, 9
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)   0.0005746  0.0009346  7.6538185   0.615    0.557
## TreatmentCUR -0.0016000  0.0012697  7.5087302  -1.260    0.245
## TreatmentTMP  0.0005007  0.0013398  4.4345996   0.374    0.726
## 
## Correlation of Fixed Effects:
##             (Intr) TrtCUR
## TreatmntCUR -0.733       
## TreatmntTMP -0.698  0.511
# All Change Against Current 
# All Change Against High Temperature

The 80% (DO) Threshold t values are slightly smaller. The variance around a MOATs effect remains significantly small. No treatment effect observed. Model re-organized/re-leveled below to compare “Current” against “High Temperature” directly

26.d) 80% Threshold - LMER releved Current 1st

levels(ksSlopes.80$Treatment)
## [1] "CHG" "CUR" "TMP"
# lmer.ksSlopes.1hr 
ksSlopes.80$Treatment <- fct_relevel(ksSlopes.80$Treatment, "CUR")
lmer.ksSlopes.80 <- lmer(CorrSlope ~ Treatment + (1|MOATS), data = ksSlopes.80)
summary(lmer.ksSlopes.80)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CorrSlope ~ Treatment + (1 | MOATS)
##    Data: ksSlopes.80
## 
## REML criterion at convergence: -395.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4943 -0.5586  0.1519  0.5739  1.4604 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. 
##  MOATS    (Intercept) 2.347e-07 0.0004845
##  Residual             1.287e-05 0.0035869
## Number of obs: 51, groups:  MOATS, 9
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)  -0.0010254  0.0008642  5.6876601  -1.187    0.283
## TreatmentCHG  0.0016000  0.0012697  7.5087302   1.260    0.245
## TreatmentTMP  0.0021007  0.0012916  3.8400048   1.626    0.182
## 
## Correlation of Fixed Effects:
##             (Intr) TrtCHG
## TreatmntCHG -0.677       
## TreatmntTMP -0.669  0.453

When comparing Current against “High Temperature” and “All Change” the T values remain small but the TMP to CUR is somewhat larger.

Still, no discernible treatment effect, no discernible MOATS effect.

26.e) 70% Threshold Dataframe - LMER

lmer.ksSlopes.70 <- lmer(CorrSlope ~ Treatment + (1|MOATS), data = ksSlopes.70)
summary(lmer.ksSlopes.70)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CorrSlope ~ Treatment + (1 | MOATS)
##    Data: ksSlopes.70
## 
## REML criterion at convergence: -431.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1536 -0.5207  0.1268  0.5546  1.5776 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  MOATS    (Intercept) 3.331e-06 0.001825
##  Residual             5.069e-06 0.002251
## Number of obs: 51, groups:  MOATS, 9
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)  -3.876e-04  1.089e-03  9.300e+00  -0.356    0.730
## TreatmentCUR  1.416e-05  1.384e-03  1.437e+01   0.010    0.992
## TreatmentTMP  6.215e-04  1.780e-03  6.780e+00   0.349    0.738
## 
## Correlation of Fixed Effects:
##             (Intr) TrtCUR
## TreatmntCUR -0.680       
## TreatmntTMP -0.612  0.416
# All Change Against Current 
# All Change Against High Temperature

The variance around a MOATs effect remains significantly small in this 70% Threshold dataset. No treatment effect observed. Model re-organized/re-leveled below to compare “Current” against “High Temperature” directly

26.f) 70% Threshold - LMER releved Current 1st

levels(ksSlopes.70$Treatment)
## [1] "CHG" "CUR" "TMP"
# lmer.ksSlopes.1hr 
ksSlopes.70$Treatment <- fct_relevel(ksSlopes.70$Treatment, "CUR")
lmer.ksSlopes.70 <- lmer(CorrSlope ~ Treatment + (1|MOATS), data = ksSlopes.70)
summary(lmer.ksSlopes.70)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CorrSlope ~ Treatment + (1 | MOATS)
##    Data: ksSlopes.70
## 
## REML criterion at convergence: -431.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1536 -0.5207  0.1268  0.5546  1.5776 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  MOATS    (Intercept) 3.331e-06 0.001825
##  Residual             5.069e-06 0.002251
## Number of obs: 51, groups:  MOATS, 9
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)  -3.734e-04  1.025e-03  9.401e+00  -0.364    0.724
## TreatmentCHG -1.416e-05  1.384e-03  1.437e+01  -0.010    0.992
## TreatmentTMP  6.073e-04  1.742e-03  6.715e+00   0.349    0.738
## 
## Correlation of Fixed Effects:
##             (Intr) TrtCHG
## TreatmntCHG -0.628       
## TreatmntTMP -0.589  0.370

No discernible treatment effect, no discernible MOATS effect. None of the “threshold confined” datasets displayed a MOATs or Treatment Effect.

Below shows the comparison is slopes values when all data points were considered.

26.g) All Points “dSlopes” Dataframe - LMER

lmer.dSlopes<- lmer(CorrSlope ~ Treatment + (1|MOATS), data = dSlopes)
## boundary (singular) fit: see ?isSingular
summary(lmer.dSlopes)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CorrSlope ~ Treatment + (1 | MOATS)
##    Data: dSlopes
## 
## REML criterion at convergence: -345.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.8039 -0.6542  0.1125  0.7677  1.8463 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  MOATS    (Intercept) 0.000e+00 0.000000
##  Residual             3.677e-05 0.006064
## Number of obs: 51, groups:  MOATS, 9
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)  -0.008107   0.001516 48.000000  -5.348 2.44e-06 ***
## TreatmentCUR -0.002224   0.002058 48.000000  -1.081    0.285    
## TreatmentTMP -0.001646   0.002144 48.000000  -0.768    0.446    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) TrtCUR
## TreatmntCUR -0.737       
## TreatmntTMP -0.707  0.521
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see ?isSingular
# All Change Against Current 
# All Change Against High Temperature

The variance around a MOATs effect remains so significantly small. No MOATs effect No treatment effect observed. Model re-organized/re-leveled below to compare “Current” against “High Temperature” directly

26.f) All Points - LMER releved Current 1st

levels(dSlopes$Treatment)
## [1] "CHG" "CUR" "TMP"
dSlopes$Treatment <- fct_relevel(dSlopes$Treatment, "CUR")
lmer.dSlopes <- lmer(CorrSlope ~ Treatment + (1|MOATS), data = dSlopes)
## boundary (singular) fit: see ?isSingular
summary(lmer.dSlopes)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CorrSlope ~ Treatment + (1 | MOATS)
##    Data: dSlopes
## 
## REML criterion at convergence: -345.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.8039 -0.6542  0.1125  0.7677  1.8463 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  MOATS    (Intercept) 0.000e+00 0.000000
##  Residual             3.677e-05 0.006064
## Number of obs: 51, groups:  MOATS, 9
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  -0.0103312  0.0013912 48.0000000  -7.426 1.64e-09 ***
## TreatmentCHG  0.0022243  0.0020576 48.0000000   1.081    0.285    
## TreatmentTMP  0.0005786  0.0020576 48.0000000   0.281    0.780    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) TrtCHG
## TreatmntCHG -0.676       
## TreatmntTMP -0.676  0.457
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see ?isSingular
# 
# # Just a chunk of the models held back case I need them.  
# 
# lmer.ksSlopes.80 <- lmer(CorrSlope ~ Treatment + (1|MOATS), data = ksSlopes.80)
# summary(lmer.ksSlopes.80)
# 
# lmer.ksSlopes.70 <- lmer(CorrSlope ~ Treatment + (1|MOATS), data = ksSlopes.70)
# summary(lmer.ksSlopes.70)
# 
# lmer.dSlopes <- lmer(CorrSlope ~ Treatment + (1|MOATS), data = dSlopes)
# summary(lmer.dSlopes)
# 
# 
# 
# # what about different rounds on different days?
Onehrplot
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

plot70
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

plot80

dSlopesplot

Slope Statistics

kable(Slope_Stats)
Avg All Points Corrected Slopes Med All Points Corrected Slopes All Points Corrected Slopes SD Avg 80% DO Corrected Slopes Med 80% DO Corrected Slopes 80% DO Corrected Slopes SD Avg 70% DO Corrected Slopes Med 70% DO Corrected Slopes 70% DO Corrected Slopes SD Avg 1hr Corrected Slopes Med 1hr Corrected Slopes 1hr Corrected Slopes SD
CHG -0.0081069 -0.0077957 0.0042656 0.0005786 0.0014299 0.0040655 -0.0004976 -0.0000416 0.0031732 -0.0017762 -0.0020364 0.0055834
CUR -0.0103312 -0.0098989 0.0066749 -0.0010072 -0.0006883 0.0032839 -0.0003071 -0.0000257 0.0022988 0.0023796 0.0010210 0.0112983
TMP -0.0097526 -0.0086015 0.0067831 0.0010753 0.0006013 0.0034942 0.0002339 0.0004077 0.0028139 -0.0025005 -0.0036506 0.0048384

Krill Slopes 1hr Summary Table

kable(ksSlopes1hr.summary, digits = 4)
Treatment sd mean median IQR n se ci
CHG 0.0056 -0.0018 -0.0020 0.0049 16 0.0014 0.0027
CUR 0.0113 0.0024 0.0010 0.0051 19 0.0026 0.0051
TMP 0.0048 -0.0025 -0.0037 0.0057 16 0.0012 0.0024

Krill Slopes (70min cutoff) Summary Table

kable(ksSlopes70.summary, digits = 8)
Treatment sd mean median IQR n se ci
CHG 0.00317323 -0.00049765 -0.00004159 0.00290097 16 0.00079331 0.00155488
CUR 0.00229879 -0.00030711 -0.00002571 0.00241889 19 0.00052738 0.00103366
TMP 0.00281395 0.00023391 0.00040771 0.00384843 16 0.00070349 0.00137884

Krill Slopes (80min cutoff) Summary Table

kable(ksSlopes80.summary, digits = 8)
Treatment sd mean median IQR n se ci
CHG 0.00406553 0.00057855 0.00142992 0.00205228 16 0.00101638 0.00199211
CUR 0.00328389 -0.00100720 -0.00068825 0.00367781 19 0.00075338 0.00147662
TMP 0.00349420 0.00107532 0.00060128 0.00515613 16 0.00087355 0.00171216

Krill Slopes (all points) Summary Table

kable(dSlopes.summary, digits = 8)
Treatment sd mean median IQR n se ci
CHG 0.00426562 -0.00810690 -0.00779566 0.00723800 16 0.00106640 0.00209015
CUR 0.00667489 -0.01033117 -0.00989889 0.00920864 19 0.00153133 0.00300140
TMP 0.00678308 -0.00975257 -0.00860152 0.00947900 16 0.00169577 0.00332371

Krill Slopes (1hr cutoff) Mixed Effects Model

summary(lmer.ksSlopes.1hr)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CorrSlope ~ Treatment + (1 | MOATS)
##    Data: ksSlopes.1hr
## 
## REML criterion at convergence: -329.1
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.68638 -0.47569  0.00437  0.51632  2.75955 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  MOATS    (Intercept) 3.441e-05 0.005866
##  Residual             4.178e-05 0.006464
## Number of obs: 51, groups:  MOATS, 9
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)
## (Intercept)   0.002713   0.003173  8.789085   0.855    0.415
## TreatmentCHG -0.004016   0.004212 14.743842  -0.953    0.356
## TreatmentTMP -0.005214   0.005467  6.253781  -0.954    0.376
## 
## Correlation of Fixed Effects:
##             (Intr) TrtCHG
## TreatmntCHG -0.616       
## TreatmntTMP -0.580  0.357

Krill Slopes (80min cutoff) Mixed Effects Model

summary(lmer.ksSlopes.80)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CorrSlope ~ Treatment + (1 | MOATS)
##    Data: ksSlopes.80
## 
## REML criterion at convergence: -395.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4943 -0.5586  0.1519  0.5739  1.4604 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. 
##  MOATS    (Intercept) 2.347e-07 0.0004845
##  Residual             1.287e-05 0.0035869
## Number of obs: 51, groups:  MOATS, 9
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)  -0.0010254  0.0008642  5.6876601  -1.187    0.283
## TreatmentCHG  0.0016000  0.0012697  7.5087302   1.260    0.245
## TreatmentTMP  0.0021007  0.0012916  3.8400048   1.626    0.182
## 
## Correlation of Fixed Effects:
##             (Intr) TrtCHG
## TreatmntCHG -0.677       
## TreatmntTMP -0.669  0.453

Krill Slopes (70min cutoff) Mixed Effects Model

summary(lmer.ksSlopes.70)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CorrSlope ~ Treatment + (1 | MOATS)
##    Data: ksSlopes.70
## 
## REML criterion at convergence: -431.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1536 -0.5207  0.1268  0.5546  1.5776 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  MOATS    (Intercept) 3.331e-06 0.001825
##  Residual             5.069e-06 0.002251
## Number of obs: 51, groups:  MOATS, 9
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)  -3.734e-04  1.025e-03  9.401e+00  -0.364    0.724
## TreatmentCHG -1.416e-05  1.384e-03  1.437e+01  -0.010    0.992
## TreatmentTMP  6.073e-04  1.742e-03  6.715e+00   0.349    0.738
## 
## Correlation of Fixed Effects:
##             (Intr) TrtCHG
## TreatmntCHG -0.628       
## TreatmntTMP -0.589  0.370

Krill Slopes (all points) Mixed Effects Model

summary(lmer.dSlopes)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CorrSlope ~ Treatment + (1 | MOATS)
##    Data: dSlopes
## 
## REML criterion at convergence: -345.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.8039 -0.6542  0.1125  0.7677  1.8463 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  MOATS    (Intercept) 0.000e+00 0.000000
##  Residual             3.677e-05 0.006064
## Number of obs: 51, groups:  MOATS, 9
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  -0.0103312  0.0013912 48.0000000  -7.426 1.64e-09 ***
## TreatmentCHG  0.0022243  0.0020576 48.0000000   1.081    0.285    
## TreatmentTMP  0.0005786  0.0020576 48.0000000   0.281    0.780    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) TrtCHG
## TreatmntCHG -0.676       
## TreatmntTMP -0.676  0.457
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see ?isSingular
#**************E*N*D*************# 
#*********************************
## END OF SCRIPT | END OF DOCUMENT 
#*********************************

END OF SCRIPT | END OF DOCUMENT